简体   繁体   中英

How to update Lambda code defined/deployed in AWS SAM/CodePipeline?

I am trying to create a CI/CD pipeline for Step/Lambda functions and a REST API in an AWS SAM template. The overall architecture is as follows: We take a multi-repository approach to source control of our Lambda functions. Each Lambda function gets its own Git repo, and its own pipeline to zip up the code and push it to an S3 bucket (eg lambda-bucket) when a commit is pushed.

A SAM template that builds out the Step/Lambda functions and a REST API is deployed via a CodePipeline that is triggered by a PUT on the S3 bucket that holds the zipped Lambda code. It is deployed via a CloudFormation ChangeSet creation step in the CodePipeline.

The Lambda functions in the SAM template looks like this:

    myFirstLambda:
    Type: AWS::Serverless::Function
    Properties:
        FunctionName: !Sub myFirstLambda-${StackStage}
        CodeUri:
            Bucket: lambda-bucket
            Key: !Sub lambdas/myFirstLambda-${StackStage}.zip
        Handler: lambda_function.lambda_handler
        Runtime: python3.8
        AutoPublishAlias: live

The issue I am having is: when I push an update to a Lambda functions' zip in the S3 lambda-bucket, the SAM template does not see a change. When the ChangeSet is created, it fails because there is nothing new to deploy. I have tried adding in a build stage that would build, package and deploy the SAM template, with the same issue as a result.

Any thoughts or fixes for this? I appreciate any help.

Please review this page:

https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-serverlessrepo-auto-publish.html

For the me "Step 4: Create the publish action" seems to be a different approach by just adding another step the the pipeline to publish it and not monitoring S3.

But I did not try it yet.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM