Sub topic 14
Reading failures and rollback states
This chapter assumes you can create and update stacks from the AWS CLI and read a template's Resources section. You will learn how a stack moves through its failure states, how to find the real cause in the stack events, and how to recover from each stuck state.
The failure model
CloudFormation treats a stack operation as all-or-nothing. If one resource fails, it tries to undo the whole operation. Every state name has three parts: the operation (CREATE, UPDATE, DELETE), an optional ROLLBACK, and the progress (IN_PROGRESS, COMPLETE, FAILED).
The states that matter most in practice:
| Status | Meaning | What you do |
|---|---|---|
| `ROLLBACK_COMPLETE` | The first create failed and everything was removed. | Read the events, then delete the stack. It cannot be updated. |
| `UPDATE_ROLLBACK_COMPLETE` | An update failed and the stack returned to its previous working state. | Fix the template and update again. |
| `UPDATE_ROLLBACK_FAILED` | The rollback itself failed. | Fix the cause, then continue the rollback. |
| `ROLLBACK_FAILED` | A failed create could not clean up. | Delete the stack, retaining stuck resources if needed. |
| `DELETE_FAILED` | A resource could not be deleted. | Fix the cause and retry, or retain the resource. |
A stack in ROLLBACK_COMPLETE is not a working stack. It holds no resources, and its only valid operation is deletion.
Find the root cause in stack events
Events are returned newest first, and one failure usually produces many FAILED lines. Only the oldest one is the cause. The others are resources that CloudFormation cancelled because of it, and their reason reads "Resource creation cancelled".
aws cloudformation describe-stack-events \
--stack-name demo \
--query "reverse(StackEvents)[?contains(ResourceStatus, 'FAILED')].[Timestamp,LogicalResourceId,ResourceStatus,ResourceStatusReason]" \
--output tablereverse() puts the oldest event first, so the first row is the one to read. The ResourceStatusReason column usually quotes the service's own error. Typical reasons include:
- Name conflicts:
demo-data already existsappears when you hard-code a name such as a bucket name. - Permissions:
User is not authorized to perform ...means the caller, or the service role if you set one, lacks an action. - Bad property values:
Invalid ...or a validation message means the value is wrong for the resource. - Limits and capacity: a service quota or an instance type that is unavailable in the Availability Zone.
- Timeouts: a resource that never became ready, or a custom resource that never sent a response.
describe-stack-events only works while the stack exists. After you delete a stack, events remain available for a limited time if you query it by stack ID rather than by name.
Keep the failed resources for inspection
By default, rollback destroys the evidence. To debug, stop CloudFormation from rolling back a create.
aws cloudformation create-stack \
--stack-name demo \
--template-body file://template.yaml \
--on-failure DO_NOTHINGThe stack ends in CREATE_FAILED with the already-created resources still in place. You can inspect them, but you cannot update the stack, so delete it when you finish. Do not use this option in automated pipelines, because it leaves partial infrastructure behind.
Recover from UPDATE_ROLLBACK_FAILED
Rollback fails when CloudFormation cannot restore a resource to its old configuration. Common causes are a resource changed or deleted outside CloudFormation, or a missing permission. Fix the cause first, then continue.
aws cloudformation continue-update-rollback --stack-name demoIf you cannot fix the cause, skip the resource using its logical ID:
aws cloudformation continue-update-rollback \
--stack-name demo \
--resources-to-skip AppBucketSkipping marks the resource as UPDATE_COMPLETE without restoring it. The stack then no longer matches any template you wrote, so run drift detection afterward.
Recover from DELETE_FAILED
The classic case is an S3 bucket that still holds objects. CloudFormation will not empty it. Empty the bucket yourself and run delete-stack again. If you decide to leave a resource behind, retain it:
aws cloudformation delete-stack \
--stack-name demo \
--retain-resources AppBucket--retain-resources is accepted only for a stack already in DELETE_FAILED. For a stack that deletes cleanly, set DeletionPolicy: Retain in the template instead.
A debugging routine
- Run
describe-stacksand note theStackStatusandStackStatusReason. - List the oldest
FAILEDevent and read its reason. - Fix the template or the environment, not the symptom.
- For
ROLLBACK_COMPLETE, delete and recreate. ForUPDATE_ROLLBACK_COMPLETE, update again. For otherFAILEDstates, use the matching recovery command above. - Preview risky updates with a change set so the failure shows up before you apply anything.
Exercise
A first create of a stack ended in ROLLBACK_COMPLETE. Your colleague runs update-stack with a corrected template, and it is rejected. Why, and what is the correct next step?
Show answer
A stack in ROLLBACK_COMPLETE holds no resources, and the only operation it accepts is deletion. Read the oldest FAILED event to confirm the cause, delete the stack, and create it again from the corrected template.
Exercise
describe-stack-events shows five FAILED events for five different resources. Which one do you investigate first, and why?
Show answer
The oldest FAILED event. The later ones are usually resources cancelled because of that first failure, and their reasons say "Resource creation cancelled".