Best way to manage code changes for application in Amazon EC2 with Auto Scaling

前端 未结 3 2084
你的背包
你的背包 2021-01-31 19:49

I have multiple instances running behind Load balancer with Auto Scaling in AWS.

Now, if I have to push some code changes to these instances and any new instances that m

3条回答
  •  忘了有多久
    2021-01-31 20:31

    We configure our Launch Configuration to use a "clean" off-the-shelf AMI - we use these: http://aws.amazon.com/amazon-linux-ami/

    One of the features of these AMIs is CloudInit - https://help.ubuntu.com/community/CloudInit

    This feature enables us to deliver to the newly spawned plain vanilla EC2 instance some data. Specifically, we give the instance a script to run.
    The script (in a nutshell) does the following:

    1. Upgrades itself (to make sure all security patches and bug fixes are applied).
    2. Installs Git and Puppet.
    3. Clones a Git repo from Github.
    4. Applies a puppet script (which is part of the repo) to configure itself. Puppet installs the rest of the needed software modules.

    It does take longer than booting from a pre-configured AMI, but we skip the process of actually making these AMIs every time we update the software (a couple of times a week) and the servers are always "clean" - no manual patches, all software modules are up to date etc.

    Now, to upgrade the software, we use a local boto script. The script kills the servers running the old code one by one. The Auto Scaling mechanism launches new (and upgraded) servers.

    Make sure to use as-terminate-instance-in-auto-scaling-group because using ec2-terminate-instance will cause the ELB to continue to send traffic to the shutting-down instance, until it fails the health check.

    Interesting related blog post: http://blog.codento.com/2012/02/hello-ec2-part-1-bootstrapping-instances-with-cloud-init-git-and-puppet/

提交回复
热议问题