CCCC
CCCC

Reputation: 6469

How to update lambda function code if the lambda code is uploaded to S3

The lambda function code(zip file) is currently being got from my S3 bucket. However, after I change my code and replace the original zip file with updated code and then run update-stack, the lambda function code seems not change in the lambda console.

Is there any way to make it work?

My json template

{
   "AWSTemplateFormatVersion": "2010-09-09",
   
   "Parameters": {
    "storageS3Bucket": {
      "Type": "String",
      "Default": "myBucket"
    }
  },
   "Resources": {
     
    "s3BucketImageStorage":{
      "Type" : "AWS::S3::Bucket",
      "Properties" : {
          "BucketName" : {
              "Ref": "storageS3Bucket"
          }
        }
    },
     "getBannerHandler": {
       "Type": "AWS::Lambda::Function",
       "Properties": {
         "FunctionName": "getBanner",
         "Handler": "getBanner.handler",
         "Role": {
           "Fn::ImportValue": {
             "Fn::Sub": "${RolesStack}-LambdaRoleArn"
           }
         },
         "Code": {
           "S3Bucket": {
             "Ref": "HandlerCodeS3Bucket"
           },
           "S3Key":"getBanner.zip"
         },
         "Runtime": "nodejs12.x"
       }
     }
   }
 }

Upvotes: 2

Views: 1560

Answers (1)

iTech
iTech

Reputation: 18440

You have few options:

  • Add file version or git commit hash to the lambda zip file name so when you do CloudFormation update-stack you pass the new zip file name as parameters.

  • Or use awscli to update the lambda function directly, but better to delete zip file first then upload it in case you want to use the same name to avoid S3 eventual consistency when replacing the same file.

Upvotes: 1

Related Questions