Home > Net >  How do I update AWS Lambda function using CloudFormation template
How do I update AWS Lambda function using CloudFormation template

Time:01-04

I want to deploy and update my lambda function code using CloudFormation Template.

My deployment workflow are:

  1. Compress my lambda function code into a zip file called Lambda
  2. Enabling s3 versioning of the s3 bucket called LambdaS3
  3. Upload the zip file into s3 bucket called LambdaS3
  4. Upload the CloudFormation template CFtemplate as below into the s3bucket LambdaS3
  5. Create the CloudFormation stack by entering "LambdaS3" as parameter LambdaS3, "Lambda" as parameter Lambdafilename and the version of the zip file as the parameter LambdafileVersion

My lambda code update workflow are:

  1. Compress my updated lambda function code into a zip file called Lambda
  2. Upload the updated zip file into the s3 bucket called LambdaS3
  3. Update the CloudFormation stack by entering the updated version of the zip file as the parameter LambdafileVersion
  • What I expected: deployment and update will be successful
  • Actual result: Get the message from AWS "There was an error creating this change set The submitted information didn't contain changes. Submit different information to create a change set." during updating the stack, while deployment is successful.

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

CodePudding user response:

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
  •  Tags:  
  • Related