- Newest
- Most votes
- Most comments
I did some research relating to this issue, and it turns out that CloudFormation does not delete S3 buckets by default if they contain objects. This is due to a safeguard mechanism to prevent accidental data loss.
Key Findings: Retain Policy Behavior– If the S3 bucket is created with a Retain deletion policy, it will persist even after stack deletion.
Bucket Not Empty – CloudFormation does not delete S3 buckets that contain objects unless explicitly configured.
Explicit Deletion Required – If you want CloudFormation to remove the bucket upon stack deletion, you need to: Empty the bucket before deleting the stack.
Before deleting the stack, ensure the bucket is empty. You can do this manually or use an AWS::Lambda::Function to automate the cleanup.
Would love to hear if this resolves your issue or if you need further clarification!
Relevant content
- asked 8 months ago
- asked 3 years ago

Adding to this that you can include a Custom Resource to your CloudFormation template that can automate the clean-up for you. I would recommend that you check to make sure that the bucket is a development or test bucket via tags first. Here is a great example from AWS that you can follow for the basics: https://repost.aws/knowledge-center/cloudformation-s3-custom-resources