[英]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:
以下是我到目前为止的步骤:
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.