Stack deletion ends in `DELETE_FAILED` with `The bucket you tried to delete is not empty` on an S3 bucket resource.
IntermediateTroubleshootingCloudFormation, CloudWatch, KMS, Secrets and Cost
Answer
Likely causes → CloudFormation does not empty buckets. A non-empty or versioned bucket blocks deletion. The same thing happens with ECR repositories that contain images and security groups still attached to ENIs.
Diagnose →
aws cloudformation describe-stack-events --stack-name app \
--query "StackEvents[?ResourceStatus=='DELETE_FAILED'].[LogicalResourceId,PhysicalResourceId,ResourceStatusReason]"
Fix →
- Empty the bucket, including all versions (see Q82), then delete the stack again
- Or keep the bucket:
aws cloudformation delete-stack --stack-name app --retain-resources LogsBucket(only allowed when the stack is inDELETE_FAILED)
Prevent → Set DeletionPolicy: Retain on data buckets, and use auto-delete custom resources (CDK autoDeleteObjects) only for ephemeral stacks.
More on CloudFormation, CloudWatch, KMS, Secrets and Cost
Updating a stack fails: `Stack:arn:aws:cloudformation:...:stack/app/... is in ROLLBACK_COMPLETE state and can not be updated.`BeginnerA stack is stuck in `UPDATE_ROLLBACK_FAILED`.AdvancedA pipeline fails with `An error occurred (ValidationError) when calling the UpdateStack operation: No updates are to be performed.`Beginner`InsufficientCapabilitiesException: Requires capabilities : [CAPABILITY_NAMED_IAM]`.BeginnerDrift detection shows `MODIFIED` on a security group and an RDS instance that someone changed in the console. How do you reconcile?AdvancedDeleting or updating a stack fails: `Export network-VpcId cannot be deleted as it is in use by app-stack`.Intermediate