- Newest
- Most votes
- Most comments
Hello.
As stated in the re:Post Agent answer, you probably have versioning enabled on your S3 bucket and old versions are still there.
There is an "Empty" button on the S3 bucket screen, so try using it to delete all the contents of the bucket.
Note that using this option will delete all objects, so be careful.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/empty-bucket.html
The issue you're experiencing is a common one when trying to delete S3 buckets through CloudFormation, especially if the bucket has versioning enabled. Here are some steps you can take to resolve this:
-
Ensure all object versions are deleted: If your bucket has versioning enabled, deleting objects doesn't remove their previous versions. You need to delete all versions of all objects before the bucket can be deleted.
-
Empty the bucket before stack deletion: CloudFormation doesn't automatically delete non-empty S3 buckets as a safeguard against accidental data loss. Before deleting the stack, make sure to empty the bucket completely, including all versions of all objects.
-
Use a lifecycle rule: If your bucket contains a large number of objects and versions, it might be more efficient to set up a lifecycle rule to delete all objects and versions automatically.
-
Retain the bucket: If you can't empty the bucket for some reason, you can use the 'RetainResources' parameter when deleting the stack. This will delete the stack but leave the S3 bucket in place, allowing you to manage it separately.
-
Force delete: As a last resort, you can use the 'FORCE_DELETE_STACK' option with the 'DeletionMode' parameter when deleting the stack. This will attempt to delete all resources in the stack, including non-empty S3 buckets.
-
Check permissions: Ensure you have the necessary IAM permissions to delete both the CloudFormation stack and the S3 bucket and its contents.
If you're dealing with a versioned bucket and need to delete all versions programmatically, you might need to use a script or AWS CLI commands to list and delete all object versions before attempting to delete the bucket through CloudFormation.
Remember, it's crucial to be certain you want to delete all data in the bucket before proceeding with these steps, as the deletion of object versions is irreversible.
Sources
S3 Bucket Not Deleted When Deleting CloudFormation Stack | AWS re:Post
Troubleshooting CloudFormation - AWS CloudFormation
Versioned Bucket Delete All Objects and bucket | AWS re:Post
As mentioned in the Document [1], You can only delete empty buckets. Deletion fails for buckets that have contents, including versions. Please refer the article [2] which has detailed explanation to delete S3 buckets. If you would like, you can also retain S3 bucket during deletion of stack or force delete stack which will retain S3 bucket automatically, please refer [3]
REFERENCES:
[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-s3-bucket.html
[2] https://repost.aws/knowledge-center/s3-delete-bucket
[3] https://repost.aws/knowledge-center/cloudformation-stack-delete-failed https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-delete-stack.html
Relevant content
- asked 2 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 4 months ago