Lesson 5 of 5 AWS CloudFormation

Troubleshooting CloudFormation Stack Failures

This lesson explains how stack events and status codes show what happened and what to do next, since the exam guide names CloudFormation errors as a deployment issue to remediate.

Learning outcomes

After completing this lesson, you will be able to:

  • Find the root cause in stack events.
  • Recover from stack status codes such as UPDATE_ROLLBACK_FAILED.
  • Resolve permissions and service role issues.

Reading stack events

The Events tab (describe-stack-events) lists every status change with a status reason. The first CREATE_FAILED or UPDATE_FAILED event is the root cause; later failures are usually cancellations. Typical reasons are invalid property values, resources that already exist with the same name, insufficient permissions, service quotas, and resources that failed to stabilise. Disable rollback (or preserve successfully provisioned resources) keeps resources after a failure for troubleshooting, and the operation can then be retried from the failure point.

Stack status codes

The following table lists the statuses that need operator action and how to recover.

StatusMeaningWhat to do
ROLLBACK_COMPLETEStack creation failed and was rolled backFix the cause, delete the stack and create it again (it cannot be updated)
ROLLBACK_FAILEDRollback after a failed create could not delete some resourcesFix the blocking resource, then delete the stack
UPDATE_ROLLBACK_FAILEDRollback after a failed update could not restore a resourceFix the resource or dependency, then ContinueUpdateRollback, optionally skipping resources
DELETE_FAILEDA resource could not be deleted (non-empty bucket, dependency, manual change)Fix or empty it, or delete again retaining that resource
UPDATE_COMPLETE_CLEANUP_IN_PROGRESSOld replaced resources are being deletedWait

The following diagram shows how each problem status is reached and resolved.

Recovering from the stack statuses that need action. ROLLBACK_COMPLETE after a failed create cannot be updated, so the cause is fixed and the stack deleted and recreated. ROLLBACK_FAILED needs the blocking resource fixed before deleting. UPDATE_ROLLBACK_FAILED needs the resource fixed and then ContinueUpdateRollback, optionally skipping resources.
Stack events name the resource and reason behind each failed status.
Match the pairs

Recovering from stack states

Exam skills 3.1.3

Match each stack status with the action that recovers it.

Log in to try this activity Interactive activities are free with an account.

Permissions and service roles

CloudFormation acts with the permissions of the user who calls it unless a service role is specified, in which case it uses that role for all operations on the stack. Service roles let operators deploy stacks without holding broad permissions themselves: they need only cloudformation:* on the stack and iam:PassRole for the service role. Templates that create IAM resources need the CAPABILITY_IAM or CAPABILITY_NAMED_IAM acknowledgement, and macros need CAPABILITY_AUTO_EXPAND. If a service role is later deleted, stack updates and deletes fail until it is recreated.

Troubleshooting scenario

Stack permission errors

Exam skills 3.1.3 · 4.1.2

Fix permission errors in stack operations.

Log in to try this activity Interactive activities are free with an account.
Worked example

UPDATE_ROLLBACK_FAILED

An update to a stack fails, and the rollback then fails too, leaving UPDATE_ROLLBACK_FAILED. The events show that rollback tried to restore an Auto Scaling group's launch template version that an administrator had deleted manually. The stack cannot be updated or deleted in this state. The operator runs continue-update-rollback with --resources-to-skip WebASG, which marks the resource as rolled back without changing it, and the stack returns to UPDATE_ROLLBACK_COMPLETE. A drift check and a corrective update then align the group with the template.

aws cloudformation describe-stack-events --stack-name web-prod \
  --query "StackEvents[?contains(ResourceStatus,'FAILED')].[Timestamp,LogicalResourceId,ResourceStatusReason]" \
  --output table
aws cloudformation continue-update-rollback --stack-name web-prod --resources-to-skip WebASG
Check yourself

A stack is in ROLLBACK_COMPLETE after a failed creation. What must be done?

Show answer

Delete it and create it again; it cannot be updated.

Exam Tips

Remember for the exam

  • The first FAILED event in the stack events is the root cause.
  • ROLLBACK_COMPLETE stacks must be deleted and recreated.
  • UPDATE_ROLLBACK_FAILED: fix the cause and continue update rollback, skipping resources if necessary.
  • DELETE_FAILED: empty buckets or retain the blocking resource.
  • Service roles need iam:PassRole; IAM resources need CAPABILITY_IAM or CAPABILITY_NAMED_IAM.