Can an Elastic Beanstalk environment be updated in Cloudformation without affecting the version deployed to it?

青春壹個敷衍的年華 提交于 2019-12-10 18:09:40

问题


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:

  1. Don't hard code the initial version into your CloudFormation template.
  2. 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.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!