4
votes

I'm trying to automate the deploy to instances in an auto scaling group.

Unfortunately I can't consider CodeDeploy or other AWS services, so I'm trying to do this only with EC2 tools.

This is my approach: i wrote a script that creates an AMI from a "master" instance (the only one I'm deploying to), then creates a new launch config with it, then updates my auto scaling group with it.

I'm trying to take advantage of the termination policies, more specifically the "oldest launch configuration" one. It works like a charm but, as you maybe already know, this only works when scaling in.

How can I update my instances when I'm not scaling in? Any suggestion on how to force the termination of the "old" instances?

Thanks for help!

1

1 Answers

3
votes

You are correct -- the Auto Scaling Termination Policy determines which instance(s) will be terminated when an Auto Scaling group scales-in (removes an instance).

Therefore, the best way to refresh your total fleet is:

  • Scale-out by increasing the Minimum size of the Auto Scaling group
  • Wait for everything to launch and stabilize
  • Scale-in by reducing the Minimum size

Depending upon your scale-in policies, this will cause your Auto Scaling group to reduce the number of instances in the group. The instances with the oldest launch configuration will be terminated first. (Alternatively, you could use OldestInstance, which would have a similar effect.)

If your scaling policies do not cause the instances to terminate, you could force the Desired Capacity to a lower number, thereby triggering the scale-in.