Skip to content

S3 Bucket Not Deleted When Deleting CloudFormation Stack

1

Hi AWS Community, I recently deployed a CloudFormation stack that included an S3 bucket. However, when I deleted the stack, I noticed that the S3 bucket was not removed from the AWS console. I expected CloudFormation to delete all resources associated with the stack, including the S3 bucket. Are there any specific settings or reasons why the bucket persists after stack deletion? Has anyone else faced this issue? What would be the best way to ensure the bucket gets deleted along with the stack? Thanks in advance for your insights!

1 Answer
1
Accepted Answer

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!

answered 10 months ago
EXPERT
reviewed 10 months ago
EXPERT
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.