Why can't I delete my S3 bucket using the Amazon S3 console or AWS CLI, even with full or root permissions?
Last updated: 2021-01-05
I'm trying to delete an Amazon Simple Storage Service (S3) bucket using the Amazon S3 console or AWS Command Line Interface (AWS CLI). I have full or root permissions to the bucket. However, my delete request fails and the bucket is still available. How can I delete the bucket?
You can't delete an S3 bucket using the Amazon S3 console if the bucket contains 100,000 or more objects. You can't delete an S3 bucket using the AWS CLI if versioning is enabled. For more information, see Deleting or emptying a bucket.Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent AWS CLI version.
To delete an S3 bucket in either scenario, first suspend versioning (if enabled), and then set up lifecycle rules to expire objects in the bucket after one day. After the objects are deleted, you can delete the bucket.
Warning: The following procedure permanently deletes any data in your S3 bucket. Data deleted and removed from a bucket can't be recovered. Before you proceed, review all the objects and data in the bucket and make sure that they are no longer needed.
Follow these steps to suspend versioning, and then set up lifecycle rules to delete objects in the bucket:
1. Open the Amazon S3 console.
2. Open the bucket that you want to delete by choosing the bucket's name.
3. (Optional) If versioning is enabled, suspend versioning on the bucket.
4. Choose the Management view.
5. Under Lifecyle Rules, choose Create lifecycle rule.
6. For Lifecycle rule name, enter a name for the lifecycle rule.
7. To run the rule on the entire bucket, choose This rule applies to all objects in the bucket. To run the rule on a certain prefix, choose Limit the scope of this rule using one or more filters. Then, enter the prefix name under Prefix.
8. Under Lifecycle rule actions, select the following:
Expire current versions of objects
Permanently delete previous versions of objects
Delete expired delete markers or incomplete multipart uploads.
9. For Expire current versions of objects, enter "1" under Number of days after object creation.
10. For Permanently delete previous versions of objects, enter "1" under Number of days after objects become previous versions.
11. For Delete expired delete markers or incomplete multipart uploads, select Delete incomplete multipart uploads. Then, enter "1" to specify Number of days.
12. Choose Create rule.
Note: If you receive the error message "This rule has prefix(es) that are overlapping with (previous_rule_name)," you can still save the rule.
The lifecycle rules run around midnight Universal Coordinated Time (UTC). After the lifecycle rules run, the objects aren't deleted immediately, but they are marked for deletion. When objects are marked for deletion, you no longer are charged for those objects. For more information, see Configuring object expiration.
If there are a large number of objects in the bucket, those objects might continue to appear in the Amazon S3 console for a few days. This condition applies especially to Amazon S3 buckets that have versioning enabled. If the bucket has versioning enabled, delete markers are created after the current version of an object is deleted. After the delete markers are at least one day old, the lifecycle rules then also clean up the delete markers. It might take a few days for the delete markers to age past one day old and for the lifecycle rules to detect their age and remove them.
After the objects are fully deleted (including delete markers), you can delete the bucket.