Using the new pipelines construct, I have successfully created a Lambda function that uses a zip file:
export class MyLambdaStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const squareNumberLambdaFunction = new lambda.Function(this, 'squareNumberLambdaFunction', {
code: lambda.Code.fromAsset('./lambda.zip'),
handler: 'SquareNumber.handler',
runtime: lambda.Runtime.PROVIDED,
tracing: lambda.Tracing.ACTIVE
})
}
This works fine if I commit the zip file with the cdk project, but I want to create the zip file in a build stage. I have verified that the zip file is created in the build stage, but I don't know how to use the zip file in the MyLambdaStack. If I try to supply the zip file as an asset in the above code, it only uses the committed zip file, or fails to compile if I don't have a zip file committed.
In the codebuild.BuildSpec, in the build phase, I have a shell script that creates a lambda.zip file, and I did a ls -al in the post_build phase to check that it was created.