Im using codepipeline, codebuild and cloudformation on AWS.
My flow is:
- Push a commit to github, this triggers the codepipeline
- Codebuild uploads (zipped) lambda functions to S3 bucket
- Cloudformation configure lambda functions
Cloudformation (simplified):
CreateDoctorLambda:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.6
Handler: lambda_function.lambda_handler
Role:
Fn::GetAtt:
- LambdaExecutionRole
- Arn
Code:
S3Bucket: !Ref LambdaFunctionS3Bucket
S3Key: CreateDoctor.zip
S3ObjectVersion: Latest <-- This value is invalid
Problem: When I update the code for lambda functions (this new code is zipped and uploaded to the S3 bucket during codebuild), the change is not deployed to the existing lambda functions.
According to AWS documentation:
To update a Lambda function whose source code is in an Amazon S3 bucket, you must trigger an update by updating the S3Bucket, S3Key, or S3ObjectVersion property. Updating the source code alone doesn't update the function.
Question: Is there any way to tell Cloudformation to use the latest version of the code stored in S3? Using S3ObjectVersion: Latest
will result in an error.
S3ObjectVersion
so that lambda will get latest s3 zip file ? – Private