AWS CloudFormation
User Guide (API Version 2010-05-15)

Monitor and Roll Back Stack Operations

Rollback triggers enable you to have AWS CloudFormation monitor the state of your application during stack creation and updating, and to roll back that operation if the application breaches the threshold of any of the alarms you've specified. For each rollback trigger you create, you specify the Cloudwatch alarm that AWS CloudFormation should monitor. AWS CloudFormation monitors the specified alarms during the stack create or update operation, and for the specified amount of time after all resources have been deployed. If any of the alarms goes to ALARM state during the stack operation or the monitoring period, AWS CloudFormation rolls back the entire stack operation.

You can set a monitoring time from the default of 0 up to 180 minutes. During this time, AWS CloudFormation monitors all the rollback triggers after the stack creation or update operation deploys all necessary resources. If any of the alarms goes to ALARM state during the stack operation or this monitoring period, AWS CloudFormation rolls back the entire stack operation. Then, for update operations, if the monitoring period expires without any alarms going to ALARM state, CloudFormation proceeds to dispose of old resources as usual. If you set a monitoring time but do not specify any rollback triggers, AWS CloudFormation still waits the specified period of time before cleaning up old resources for update operations. You can use this monitoring period to perform any manual stack validation desired, and manually cancel the stack creation or update as necessary. If you set a monitoring time of 0 minutes, AWS CloudFormation still monitors the rollback triggers during stack creation and update operations and rolls back the operation if an alarm goes to ALARM state. Then, for update operations with no breaching alarms, it begins disposing of old resources immediately once the operation completes.

By default, CloudFormation only rolls back stack operations if an alarm goes to ALARM state, not INSUFFICIENT_DATA state. To have AWS CloudFormation roll back the stack operation if an alarm goes to INSUFFICIENT_DATA state as well, edit the CloudWatch alarm to treat missing data as breaching. For more information, see Configuring How CloudWatch Alarms Treats Missing Data in Amazon CloudWatch User Guide.

AWS CloudFormation does not monitor rollback triggers when it rolls back a stack during an update operation.

You can add a maximum of five rollback triggers. To add a rollback trigger, you specify the ARN (Amazon Resource Name) of the CloudWatch alarm. Currently, only AWS::CloudWatch::Alarm types can be used as rollback triggers.

If a given Cloudwatch alarm is missing, the entire stack operation fails and is rolled back.

Be aware that access to Amazon CloudWatch requires credentials. Those credentials must have permissions to access AWS resources, such as retrieving CloudWatch metric data about your cloud resources. For more information, see Authentication and Access Control for Amazon CloudWatch in Amazon CloudWatch User Guide.

To add rollback triggers during stack creation or updating

  1. During creating or updating a stack, on the Options page, go to Rollback Triggers.

  2. Specify a monitoring time between 0 and 180 minutes. The default is 0.

  3. Enter the ARN of the Cloudwatch alarm you want to use as a rollback trigger, and click the plus icon. You can add a maximum of five rollback triggers.

To add rollback triggers to a change set

  1. During creating or updating a change set, on the Options page, go to Rollback Triggers.

  2. Specify a monitoring time between 0 and 180 minutes. The default is 0.

  3. Enter the ARN of the Cloudwatch alarm you want to use as a rollback trigger, and click the plus icon. You can add a maximum of five rollback triggers.

To view rollback triggers for a stack

  • There are two ways to view rollback triggers for a given stack:

    • On the Stacks page, select the checkbox for the stack you wish to view, and then select the Rollback Triggers tab in the detail section.

    • On the Stack Detail page, go to the Rollback Triggers section.