问题
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).
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.
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?
回答1:
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.
Instead of deploying your version from Code Pipeline directly to Elastic Beanstalk, do the following:
- Don't hard code the initial version into your CloudFormation template.
- Have the version being deployed hooked to an input parameter to your CloudFormation stack. For example, have a input parameter be the version build number, and construct in your template a URL to that as your version source.
- When you deploy, instruct Code Pipeline to update your stack with the updated build number. CloudFormation should take over by building a new URL and deploying the version.
An Example:
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"
}
}
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.
来源:https://stackoverflow.com/questions/48791799/can-an-elastic-beanstalk-environment-be-updated-in-cloudformation-without-affect