Interview Prep/AWS/CloudFormation, CloudWatch, KMS, Secrets and Cost

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 →

  1. Empty the bucket, including all versions (see Q82), then delete the stack again
  2. Or keep the bucket: aws cloudformation delete-stack --stack-name app --retain-resources LogsBucket (only allowed when the stack is in DELETE_FAILED)

Prevent → Set DeletionPolicy: Retain on data buckets, and use auto-delete custom resources (CDK autoDeleteObjects) only for ephemeral stacks.

aws All AWS questions Roadmap: Cloud cost & architecture

More on CloudFormation, CloudWatch, KMS, Secrets and Cost