简体   繁体   English

如何更新在 AWS SAM/CodePipeline 中定义/部署的 Lambda 代码?

[英]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.我正在尝试在 AWS SAM 模板中为 Step/Lambda 函数和 REST API 创建 CI/CD 管道。 The overall architecture is as follows: We take a multi-repository approach to source control of our Lambda functions.整体架构如下: 我们采用多存储库方法对 Lambda 函数进行源代码控制。 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.每个 Lambda 函数都有自己的 Git 存储库和自己的管道,用于压缩代码并将其推送到 S3 存储桶(例如 lambda-bucket)。

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.构建 Step/Lambda 函数和 REST API 的 SAM 模板是通过 CodePipeline 部署的,CodePipeline 由保存压缩 Lambda 代码的 S3 存储桶上的 PUT 触发。 It is deployed via a CloudFormation ChangeSet creation step in the CodePipeline.它通过 CodePipeline 中的 CloudFormation ChangeSet 创建步骤进行部署。

The Lambda functions in the SAM template looks like this: SAM 模板中的 Lambda 函数如下所示:

    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.我遇到的问题是:当我将更新推送到 S3 lambda 存储桶中的 Lambda 函数的 zip 时,SAM 模板没有看到更改。 When the ChangeSet is created, it fails because there is nothing new to deploy.创建 ChangeSet 时,它会失败,因为没有任何新内容可供部署。 I have tried adding in a build stage that would build, package and deploy the SAM template, with the same issue as a result.我曾尝试添加一个构建阶段来构建、打包和部署 SAM 模板,结果出现了同样的问题。

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 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.对我来说,“第 4 步:创建发布操作”似乎是一种不同的方法,只需在管道中添加另一个步骤来发布它,而不是监控 S3。

But I did not try it yet.但我还没有尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS CodePipeline CodeBuild SAM Lambda - AWS CodePipeline CodeBuild SAM Lambda AWS CodePipeline,CodeDeploy,SAM和Lambda:如何(相互)连接它们? - AWS CodePipeline, CodeDeploy, SAM and Lambda: how to (inter)connect those? API 网关的 lambda 的 AWS SAM 更新函数代码 - AWS SAM update function code of lambda of an API Gateway 如何使用 AWS SAM 更新现有 lambda function - How to update existing lambda function using AWS SAM 如何使用 SAM 对 AWS Lambda 环境变量进行编码? - How do I code AWS Lambda env variables using SAM? AWS CodePipline (CI/CD) 更新现有 AWS Lambda 的代码(不是使用 CloudFormation 或 SAM 创建) - AWS CodePipline (CI/CD) to update the code of an existing AWS Lambda (not created with CloudFormation or SAM) 如何在 SAM 项目中使用 codepipeline? - How to work with codepipeline in SAM project? 如何调用也在 AWS SAM 模板中定义的另一个 lambda 函数? - How can I invoke another lambda function also defined in AWS SAM template? AWS SAM-如何将参数传递给Lambda函数 - AWS SAM - How to pass parameters to Lambda Function 如何使用 AWS 代码部署而不使用 SAM 部署简单的 AWS lambda function? - How do i deploy a simple AWS lambda function using AWS code deploy without using SAM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM