Rolling Update with AWS CloudFormation

Michael Wittig – 18 Jan 2016

Updating all EC2 instances in an Auto Scaling Group becomes complex and expensive when done manually. If you follow the immutable infrastructure approach you will roll out a new version by creating new EC2 instances. You never change the old instances. But how do you deploy security patches of the OS or a new version of your application automatically? One option is using AWS CloudFormation.

CloudFormation supports the UpdatePolicy attribute for Auto Scaling Groups. You can define that CloudFormation performs a rolling update of instances whenever the Launch Configuration changes. A rolling update will roll out your change in small batches.

Here is an example. Let’s say we have 4 EC2 instances running version A (grey) and a batch size of 2. Now we roll out version B (dark). Have a look at the following animation.

Rolling update animation


Looking for a new challenge?

  • tecRacer

    Cloud Consultant

    tecRacer • Premier AWS Consulting Partner • Germany, Austria, Portugal, and Switzerland
    AWS only Infrastructure as Code EC2 Containers Serverless
  • tecRacer

    Cloud Migration Specialist

    tecRacer • Premier AWS Consulting Partner • Germany, Austria, Portugal, and Switzerland
    Lift&Shift Transformation EC2 RDS VPC

  1. Two EC2 instances with version B are started (blue).
  2. Wait until both new EC2 instances running version B are in service (dark). You now have 6 EC2 instances running.
  3. Terminate the two oldest EC2 instances running version A. You now have 4 EC2 instances running.
  4. Two EC2 instances with version B are started (blue).
  5. Wait until both new EC2 instances running version B are in service (dark). You now have 6 EC2 instances running.
  6. Terminate the two oldest EC2 instances running version A. You now have 4 EC2 instances running.
  7. Done.

The following CloudFormation template is enriched with some vocal comments and line highlighting. Press the play button and enjoy the show.

How do you like CloudFormation templates annotated with voice? Let me know!

Try rolling updates with our CloudFormation template:

  1. Launch Stack
  2. Click Next to proceed with the next step of the wizard.
  3. Specify a name and all parameters for the stack. Set VersionParameter to 1.
  4. Click Next to proceed with the next step of the wizard.
  5. Click Next to skip the Options step of the wizard.
  6. Click Create to start the creation of the stack.
  7. Wait until the stack reaches the state CREATE_COMPLETE.
  8. Open the Outputs tab and click on the provided ELB URL. You should see a white page that contains Version 1 text.
  9. In the CloudFormation console, select the stack, click the Actions button at the top, select Update Stack.
  10. Click Next to proceed with the next step of the wizard.
  11. Change the VersionParameter to 2.
  12. Click Next to proceed with the next step of the wizard.
  13. Click Next to skip the Options step of the wizard.
  14. Click Update to update the stack.
  15. Go back to the page (ELB URL) and reload every now and then. After a few minutes it should switch to Version 2.
  16. Don’t forget to delete the CloudFormation stack!

Become a cloudonaut supporter

Michael Wittig

Michael Wittig ( Email, Twitter, or LinkedIn )

We launched the cloudonaut blog in 2015. Since then, we have published 350 articles, 45 podcast episodes, and 38 videos. It's all free and means a lot of work in our spare time. We enjoy sharing our AWS knowledge with you.

Please support us

Have you learned something new by reading, listening, or watching our content? With your help, we can spend enough time to keep publishing great content in the future. Learn more

$
Amount must be a multriply of 5. E.g, 5, 10, 15.

Thanks to Alan Leech, Alex DeBrie, ANTHONY RAITI, Christopher Hipwell, Jaap-Jan Frans, Jason Yorty, Jeff Finley, Jens Gehring, jhoadley, Johannes Grumböck, John Culkin, Jonas Mellquist, Juraj Martinka, Kamil Oboril, Ken Snyder, Ross Mohan, Ross Mohan, sam onaga, Satyendra Sharma, Shawn Tolidano, Thorsten Hoeger, Todd Valentine, Victor Grenu, and all anonymous supporters for your help! We also want to thank all supporters who purchased a cloudonaut t-shirt.