Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update new instances started by AWS auto scaling?

We use AWS cloudformation service to initialize our stack, and set up the auto scaling service to bring up new app servers when load is rising.

My understanding is that Auto Scaling can only start predefined AMI as new instances. These instances could be different from other running instances, because we may have updated packages/source code deployed on those instances.

How can I bring the new instances up-to-date? Should I update the AMIs everytime I deploy something new to the running instances? Or is there anyway to trigger auto-deployment on new instances (Opsworks) when auto scaling?

I am new to AWS, so pardon me if my question is rudimentary.

like image 602
NeoWang Avatar asked Jul 18 '15 14:07

NeoWang


2 Answers

There are multiple ways of doing this. My preferred approach is never to touch the servers directly, but instead create a new AMI whenever I deploy a new version of the software.

To do this, use the AutoScalingRollingUpdate property for the auto-scaling group. When you then change ImageId for the launch configuration, AWS will automatically replace your old servers with new ones as a rolling upgrade.

I have a simple deploy script that creates a new AMI, replaces ImageId in the template, and then does a stack update - AWS takes care of the rest.

like image 134
bsvingen Avatar answered Sep 21 '22 23:09

bsvingen


When creating EC2 instances from Beanstalk, it automatically creates a AutoScaling Group and Launch Configuration based on the specified environment selections. Creating the instance from base AMI is done using a custom code call user data which includes the shell script to create folders and install relevant software.

You can add a new shell scripts or commands there to do your custom work before starting a new instance. This way it is much simpler. e.g. you can run yum update before starting a instance

To find user data section Go to EC2 Console -> Go to launch configurations section (on left) -> Select the correct launch configuration and copy it -> Click view user data -> Add your scripts and commands as required -> Modify the relevant Auto Scaling group to point to the new launch configuration

like image 24
Ashan Avatar answered Sep 20 '22 23:09

Ashan