I'm using CDK go to create the lambda resources with go language. As we know the go lambda need to be build to binary before upload to lambda. The SAM support auto-build function when using sam build & deploy with Makefile:
Here is an example:
MyLambda:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
Properties:
Description: "Code of MyLambda"
CodeUri: lambda-code/
Handler: bin/main
Runtime: go1.x
Architectures:
- x86_64
MemorySize: 128
But for CDK, I need to build lambda code in separate step before using CDK deploy:
Here is an example:
fn := awslambda.NewFunction(stack, jsii.String("ddbreader"), &awslambda.FunctionProps{
Runtime: awslambda.Runtime_GO_1_X(),
Handler: jsii.String("bin/reader"),
MemorySize: jsii.Number(128),
Timeout: awscdk.Duration_Seconds(jsii.Number(10)),
Code: awslambda.Code_FromAsset(jsii.String("app/ddbreader"), nil),
CurrentVersionOptions: &awslambda.VersionOptions{
RemovalPolicy: awscdk.RemovalPolicy_DESTROY,
RetryAttempts: jsii.Number(1),
},
LogRetention: awslogs.RetentionDays_FIVE_DAYS,
})
The CDK code for lambda creation is here:
https://github.com/zhang1980s/ddb-stream-latency/blob/main/app/app_main.go
I'm planing to use CDK to create a codepipeline to deploy all AWS resources including lambda code. I understand the lambda build step could be done by codebuild but I would understand if the go code building has been encapsulated in CDK so that I don't need to write the buildspec logic separately. Please guide me how to perform lambda go auto build function in CDK. Thanks!
The CDK code for codepipeline creation.
https://github.com/zhang1980s/ddb-stream-latency/blob/main/pipeline/pipeline.go