I want to deploy and update my lambda function code using CloudFormation Template.
My deployment workflow are:
Lambda
LambdaS3
LambdaS3
CFtemplate
as below into the s3bucket LambdaS3
LambdaS3
, "Lambda" as parameter Lambdafilename
and the version of the zip file as the parameter LambdafileVersion
My lambda code update workflow are:
Lambda
LambdaS3
LambdafileVersion
My template is as below
AWSTemplateFormatVersion: "2010-09-09"
Metadata: ""
Description: ""
Parameters:
LambdaS3:
Description: Api Gateway Authorizer Lambda S3Bucket Name
Type: String
Lambdafilename:
Description: Api Gateway Authorizer Lambda file Name (Latest)
Type: String
LambdafileVersion:
Description: Lambda zip file version
Type: String
Transform: AWS::Serverless-2016-10-31
Resources:
LambdaFunction:
DeletionPolicy: "Delete"
Type: "AWS::Serverless::Function"
Properties:
Description: ""
FunctionName: "LambdaFunction"
Handler: "lambda_function.lambda_handler"
CodeUri:
Bucket: !Ref LambdaS3
Key: !Sub '${Lambdafilename}.zip'
Version: !Ref LambdafileVersion
MemorySize: 512
Role: !GetAtt IAMRole2.Arn
Runtime: "python3.8"
Timeout: 20
Tracing: "PassThrough"
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery10Minutes
This does not work because you are using CodeDeploy. If you want to update functions they way you are trying, then you have to remove the following from your code:
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery10Minutes
Follow up:
Instead of removing DeploymentPreference
property, adding AutoPublishCodeSha256
is the right solution.
According to AWS docs,
"This property addresses a problem that occurs when an AWS SAM template has the following characteristics: the DeploymentPreference object is configured for gradual deployments (as described in Deploying serverless applications gradually), the AutoPublishAlias property is set and doesn't change between deployments, and the CodeUri property is set and doesn't change between deployments."
"This scenario can occur when the deployment package stored in an Amazon Simple Storage Service (Amazon S3) location is replaced by a new deployment package that contains updated Lambda function code, but the CodeUri property remains unchanged (as opposed to the new deployment package being uploaded to a new Amazon S3 location and the CodeUri being changed to the new location)."
The described scenario is exactly my case. And after adding AutoPublishCodeSha256
property, my stack can be updated with the existance of DeploymentPreference
property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.