简体   繁体   English

如何让Cloud Formation创建更改集以更新我的Lambda函数?

[英]How do I get Cloud Formation to create a changeset to update my Lambda functions?

I have a Lambda function which I've verified to work correctly. 我有一个Lambda函数,我已经验证它可以正常工作。 I'm able to update the function by hand on the command line using "update-function-code" but I've been trying to get it working with Code Pipeline and Cloud Formation. 我可以使用“update-function-code”在命令行上手动更新函数,但我一直在尝试使用Code Pipeline和Cloud Formation。 Here are the steps I have so far: 以下是我到目前为止的步骤:

  1. Source - fetch the code from github. Source - 从github获取代码。 This works correctly. 这工作正常。
  2. Build - test the code in Solano (3rd party CI). 构建 - 在Solano中测试代码(第三方CI)。 This works too and on the last stage it zips up the repo and uploads it to my S3 bucket. 这也是有效的,在最后一个阶段它会压缩回购并将其上传到我的S3存储桶。
  3. Deploy - This is the "deploy" action category with the action mode "create or replace a change set". 部署 - 这是“部署”操作类别,其操作模式为“创建或替换更改集”。 This doesn't work if the Lambda function already exists. 如果Lambda函数已存在,则此方法无效。
  4. Beta - Execute the changeset. Beta - 执行变更集。 This works if the change set was generated correctly. 如果正确生成更改集,则此方法有效。

My samTemplate.yml looks like this: 我的samTemplate.yml看起来像这样:

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: My Lambda function Resources: LambdaFunction: Type: AWS::Serverless::Function Properties: FunctionName: MyLambdaExecute Description: My Lambda function Handler: myhandler.handler Runtime: nodejs6.10 CodeUri: s3://mybucket/mydirectory/mylambdacode.zip AutoPublishAlias: Staging Timeout: 30 DeploymentPreference: Type: AllAtOnce

If the lambda function with the name "MyLambdaExecute" doesn't exist and I push up code to github, it works perfectly. 如果名为“MyLambdaExecute”的lambda函数不存在,并且我将代码推送到github,则它可以完美地运行。 But if I modify some code and push again it runs the first two steps, but then generates an empty change set with the status: 但是,如果我修改了一些代码并再次按下它会运行前两个步骤,但随后会生成一个空状态更改集,其状态为:

FAILED - No updates are to be performed. 失败 - 不执行任何更新。

I'm not sure what I have to do to get it to publish a new version. 我不知道我要做些什么才能让它发布新版本。 How do I get it to realize it needs to create a new changeset? 如何让它意识到需要创建一个新的变更集?

I believe you are receiving the "No updates" message because technically nothing is changing in your CloudFormation template. 我相信您收到了“无更新”消息,因为从技术上讲,您的CloudFormation模板中没有任何变化。 When attempting to build the changeset, the contents of the S3 file are not examined. 尝试生成变更集时,不检查S3文件的内容。 It just sees that none of the CloudFormation resource properties have changed since the previous deployment. 它只是看到自上次部署以来没有任何CloudFormation资源属性发生了变化。

Instead, you may use a local relative path for the CodeUri, and aws cloudformation package can upload the file to a unique S3 path for you. 相反,您可以使用CodeUri的本地相对路径, aws cloudformation package可以将文件上传到唯一的S3路径。 This ensures that the template changes each time and the new Lambda code is recognized/deployed. 这可确保模板每次都更改,并识别/部署新的Lambda代码。 For example: 例如:

aws cloudformation package --template-file samTemplate.yml --output-template-file sam-output-dev.yml --s3-bucket "$CodePipelineS3Bucket" --s3-prefix "$CloudFormationPackageS3Prefix"

This command can be put into the build step before your create/execute changeset steps. 在创建/执行变更集步骤之前,可以将此命令放入构建步骤。

To see an demonstration of this entire flow in practice, you can look at this repository , although I will warn that it's a bit outdated thanks to the new features released at the end of 2017. (For example, I was publishing Lambda aliases manually via extra steps because it was written pre- AutoPublishAlias .) 要在实践中看到整个流程的演示,您可以查看此存储库 ,尽管由于2017年底发布的新功能,我会警告它有点过时。(例如,我通过手动发布Lambda别名额外的步骤,因为它是在AutoPublishAlias之前AutoPublishAlias 。)

暂无
暂无

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

相关问题 如何获取 Cloud Formation 特定资源属性的 AWS Lambda 函数的 ARN? - How do I get the ARN of an AWS Lambda function for a Cloud Formation specific resource property? 我们如何使用 Cloud Formation 为 Lambda 设置动态变量 - How do we set dynamic variables for Lambda using Cloud Formation 如何将 AWS 无服务器应用程序项目更改为仅部署为 lambda 功能? (没有API网关和云编队) - How to change an AWS Serverless application project to just deploy as lambda functions? (No API gateway and cloud formation) 如何使用云编队模板自动调整DynamoDB? - How Do I autoscale DynamoDB with a Cloud Formation Template? 如何使用对流层将记录集数组添加到云形成中? - How do I add an array of RecordSets into Cloud Formation using troposphere? Lambda API 结果作为在 Cloud Formation 中创建 AWS 资源的条件 - Lambda API result as a condition to create AWS resource in Cloud Formation 使用 Cloud Formation 从 Lambda 获取价值并检查分支的条件 - Get Value from a Lambda using Cloud Formation and check condition to branch 如何在 lambda 云形成模板中添加 vpcconfig 部分 - how to add vpcconfig section in lambda cloud formation template 如何通过云形成部署java 17 lambda function - How to deploy java 17 lambda function through cloud formation AWS Lambda - 我如何从 2 个不同的云监视触发器调用不同的函数 - AWS Lambda - How do i invoke different functions from 2 different cloud watch triggers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM