AWS CDK AWS Lambda Go Alpha

raw JSON →
2.252.0a0 verified Fri May 01 auth: no python

Alpha CDK construct library for deploying AWS Lambda functions written in Go. Provides the GoCode class to bundle Go code with build, dependencies, and bundling options. Part of the AWS CDK, version 2.252.0a0, alpha quality with frequent releases tied to CDK core.

pip install aws-cdk-aws-lambda-go-alpha==2.252.0a0
error ModuleNotFoundError: No module named 'aws_cdk.aws_lambda_go_alpha'
cause Missing installation of the alpha package or import path incorrect.
fix
Install: pip install aws-cdk-aws-lambda-go-alpha[=version]. Import: from aws_cdk.aws_lambda_go_alpha import GoCode.
error Error: Failed to bundle Go code: no go.mod file found
cause The asset path does not contain a go.mod file or points to a single file instead of a directory.
fix
Ensure path is a directory with a valid Go module (go.mod present). Use cmd to specify build command.
error Runtime.InvalidEntrypoint: 'handler' is not a valid entry point
cause Handler name mismatch or runtime not set to PROVIDED_AL2.
fix
Set runtime=Runtime.PROVIDED_AL2 and handler='main' (matches compiled binary name).
deprecated The alpha module 'aws-cdk-aws-lambda-go-alpha' is in alpha status. The API may change in breaking ways in future releases.
fix Pin to a specific alpha version and test upgrades carefully.
gotcha GoCode.from_asset expects a directory containing a Go module (go.mod). If you use a single file, bundling may fail.
fix Ensure the path points to a directory with go.mod and source files.
gotcha The runtime for Go Lambda must be either Runtime.PROVIDED_AL2 or Runtime.PROVIDED (not a runtime like Python/Node). Using wrong runtime causes invocation errors.
fix Set runtime=Runtime.PROVIDED_AL2 when using GoCode.
breaking Versions before 2.25.0 used a different import path (`aws_cdk.aws_lambda_go`). The module was moved to alpha prefix.
fix Update imports to `from aws_cdk.aws_lambda_go_alpha import GoCode`.

Minimal CDK stack defining a Go Lambda function using GoCode with asset bundling.

import aws_cdk as cdk
from aws_cdk.aws_lambda import Function, Runtime, Code
from aws_cdk.aws_lambda_go_alpha import GoCode

class MyStack(cdk.Stack):
    def __init__(self, scope, id, **kwargs):
        super().__init__(scope, id, **kwargs)
        # Bundles Go code from the specified directory
        go_code = GoCode.from_asset(
            path="./my-go-lambda",
            cmd=["go", "build", "-o", "/asset/main"],
        )
        Function(
            self, "GoFunction",
            runtime=Runtime.PROVIDED_AL2,  # Use custom runtime for Go
            handler="main",
            code=go_code,
        )

app = cdk.App()
MyStack(app, "GoLambdaStack")
app.synth()