Friday 8 June 2018

AWS cloudformation dry run mode, review changes before applying them

What:

AWS Cloudformation

Problem:

You're making some changes to your cloudformation template, but before you apply it you would like to know what will be changed, what will be restarted or terminated.

Solution:

Amazon Web Services provides useful tool called "Change Sets", which is simply a dry-run or for those who use Puppet noop mode, it’s simply an AWS way of generating a preview of what the stack update will do.

This should prevent from unexpected outages, reboots or terminations when running the stack updates.

How to use change sets?

Let's create example stack first:
aws cloudformation create-stack --stack-name example --template-body file://templates/example.yml --parameters file://parameters/example.json

Now make changes to your CF template and safe.

To create the change set run below command:
aws cloudformation create-change-set --stack-name example --template-body file://templates/example.yml --parameters file://parameters/example.json --change-set-name example-changeset1
To get a preview:
aws cloudformation describe-change-set --stack-name example --change-set-name example-changeset1 | jq '.Changes[]'
Using Amazon console to preview the changes might be a bit easier, to do that  navigate to your Cloudformation stack and select “Change Sets” tab, then click on the Change Set you just created.

No comments:

Post a Comment