可以在Cloudformation中更新Elastic Beanstalk环境而不影响部署到该环境的版本吗? [英] Can an Elastic Beanstalk environment be updated in Cloudformation without affecting the version deployed to it?
问题描述
我正在使用Cloudformation创建一个Elastic Beanstalk环境。我必须创建一个ApplicationVersion只是为了将其启动并将其输入到环境的定义中。我创建了其他ApplicationVersions并以其他方式(CodePipeline)将它们部署到集群。
I am creating an Elastic Beanstalk environment using Cloudformation. I have to create an ApplicationVersion just to get it started and feed it into the definition of the environment. I create other ApplicationVersions and deploy them to the cluster in other ways (CodePipeline).
现在,每次我需要更新Cloudformation堆栈以更改某些其他基础结构时,甚至尽管它没有列出这是潜在的资源更改,但它会将ApplicationVersion回滚到最初的版本,而我不得不再次手动将环境更新为最新版本。
Now, every time I need to update the Cloudformation stack to change some other infrastructure, even though it doesn't list that as a potential resource change, it rolls back the ApplicationVersion to the initial one, and I'm having to manually update the environment to the latest version again.
我知道发生了什么事-Cloudformation只是试图按照模板描述的那样保留堆栈。我只定义了初始ApplicationVersion,因为它是Beanstalk环境的要求。还有其他方法吗?
I know what's going on - Cloudformation is just trying to keep the stack as the template describes it. I only ever defined the initial ApplicationVersion because it's a requirement for the Beanstalk environment. Is there any other way?
推荐答案
CloudFormation希望受到控制。根据执行的堆栈更新,CloudFormation将根据模板中定义的内容重新创建版本。
CloudFormation wants to be in control. Depending on the stack updates you perform, CloudFormation will re-create the version according to what's defined in the template.
不是将您的版本从Code Pipeline直接部署到Elastic Beanstalk ,请执行以下操作:
Instead of deploying your version from Code Pipeline directly to Elastic Beanstalk, do the following:
- 不要将初始版本硬编码到CloudFormation模板中。
- 已将要部署的版本挂钩到CloudFormation堆栈的输入参数。例如,将输入参数作为版本内部版本号,并在模板中构造一个指向该URL的URL作为版本源。
- 部署时,指示代码管道使用以下命令更新堆栈更新的内部版本号。 CloudFormation应该通过构建新URL并部署版本来接管。
示例:
假设您的堆栈中有参数 ZipBucket
和 ZipObject
,您可以在 AWS :: ElasticBeanstalk :: ApplicationVersion
资源上执行以下操作:
Assuming you have a parameter ZipBucket
and ZipObject
in your stack, you can do the following on your AWS::ElasticBeanstalk::ApplicationVersion
resource:
"SourceBundle" : {
"S3Bucket" : {
"Ref" : "ZipBucket"
},
"S3Key" : {
"Ref" : "ZipObject"
}
}
另一种选择是使用 BuildNumber
参数,然后在 S3Key
Fn :: Join >属性以从内部版本号构建URL。
Another option is to have a BuildNumber
parameter, and then use Fn::Join
in the S3Key
property to build a URL out of the build number.
这篇关于可以在Cloudformation中更新Elastic Beanstalk环境而不影响部署到该环境的版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!