Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud formation - updating a stack behind an elb doesnt update the AMI

We are powering our AWS EC2 instances using cloud formation. We have 3 different stacks - testing, staging and production. Our workflow to update the images for any of the stacks is as follows:

  1. Update a 'golden master' instance
  2. Snapshot the golden master to a disk image
  3. Change the ami reference in our cloud-formation config (via a json file) for a given stack and update the stack.

This brings down the instances in the stack + re-provisions them with the new disk image.

We've had no problems with our testing or staging stacks, which contain a single ec2 instance each. Each time we update, the image is replaced no problem.

Our production stack doesn't seem to be working in the same way :-(. It contains (at least) 2 instances sitting behind a load balancer. When we update this stack in the same way, the ec2 instances are not refreshed straight away (i.e after the update is completed, the boxes are still running from the previous disk image). The good news is the new images are used when the load balancer autoscales.

Could there be a conflict between the load balancing rules and cloud formation?

Any insight would be greatly appreciated

like image 472
Rob Squires Avatar asked Aug 02 '13 08:08

Rob Squires


People also ask

What happens when a CloudFormation stack is updated?

When you update a stack, you submit changes, such as new input parameter values or an updated template. AWS CloudFormation compares the changes you submit with the current state of your stack and updates only the changed resources.

Can we update stack in CloudFormation?

To update a AWS CloudFormation stack (console)In the AWS CloudFormation console , from the list of stacks, select the running stack that you want to update. In the stack details pane, choose Update. If you haven't modified the stack template, select Use current template, and then choose Next.


1 Answers

OK - Done some experiments. You need to define an update policy for the scaling group. By defining an update policy, any change in the launch configuration will then trigger an update. Without this - an update won't be triggered.

You don't need an ELB in order to trigger the rolling update, but if you have one, it also won't interfere with it.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html

like image 174
Pete - MSFT Avatar answered Sep 17 '22 03:09

Pete - MSFT