Why can't I delete my S3 bucket through the Amazon S3 console or AWS CLI, even with full or root permissions?

4 分的閱讀內容
0

I want to use the Amazon Simple Storage Service (Amazon S3) console or AWS Command Line Interface (AWS CLI) to delete an Amazon S3 bucket. I have full or root permissions to the bucket, but my delete request fails and the bucket's still available.

Short description

You can't delete an S3 bucket in the Amazon S3 console if the bucket contains a large number of objects. You can't use the AWS CLI to delete an S3 bucket with versioning if the bucket contains objects or object versions. For more information, see Deleting 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, suspend versioning if you previously turned it on. Then, set up lifecycle rules to expire objects in the bucket after one day. After you delete all objects, you can delete the bucket.

Resolution

Warning: The following procedure permanently deletes any data in your S3 bucket. You can't recover data after you delete and remove it from a bucket. Before you proceed, review all the objects and data in the bucket to make sure that you no longer need them.

To suspend versioning and then set up lifecycle rules to delete objects in the bucket, follow these steps:

  1. Open the Amazon S3 console.
  2. Choose the bucket that you want to delete.
  3. If you turned on versioning for the bucket, then suspend versioning.
  4. Choose the Management tab.
  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 options:
    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: Even if you receive a "This rule has prefix(es) that are overlapping with (previous_rule_name)" error message, you can still save the rule.

The lifecycle rules run around midnight Universal Coordinated Time (UTC). After the lifecycle rules run, the objects don't delete immediately, but the lifecycle rules mark them for deletion. Objects that are marked for deletion don't incur billing costs. For more information, see Expiring objects.

If there are a large number of objects in the bucket, then those objects might appear in the Amazon S3 console for a few days. This condition applies especially to Amazon S3 buckets with versioning. If the bucket has versioning, then Amazon S3 creates delete markers after it deletes the current version of an object. After the delete markers are at least one day old, the lifecycle rules also clean up the delete markers. Therefore, it might take a few days for the lifecycle rules to detect the delete markers and remove them.

After your lifecycle rules fully delete all objects, including delete markers and any noncurrent versions, you can delete the bucket.

Related information

Managing your storage lifecycle

AWS 官方
AWS 官方已更新 6 個月前