How do I empty an Amazon S3 bucket using a lifecycle configuration rule?
Last updated: 2020-12-23
I have an Amazon Simple Storage Service (Amazon S3) bucket that stores millions of objects. I want to empty the bucket so that I won't be charged for storage anymore. How can I empty the bucket using a lifecycle configuration rule?
Follow these steps to create a lifecycle rule that expires current versions of objects and permanently delete previous versions of objects:
- Open the Amazon S3 console.
- From the list of buckets, choose the bucket that you want to empty.
- Choose the Management tab.
- Choose Create lifecycle rule.
- For Lifecycle rule name, enter a rule name.
- For Choose a rule scope, select This rule applies to all objects in the bucket.
- Select I acknowledge that this rule will apply to all objects in the bucket.
- For 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
- For Expire current versions of objects, enter 1 for Number of days after object creation.
- For Permanently delete previous versions of objects, enter 1 for Number of days after objects become previous versions.
- For Delete expired delete markers or incomplete multipart uploads, select Delete incomplete multipart uploads. Then, for Number of days, enter 1.
- Choose Create rule.
Amazon S3 runs lifecycle rules once every day. After the first time Amazon S3 runs the rules, all objects eligible for expiration are marked for deletion and you're no longer be charged for those objects. It can take a few days for the rules to run until the bucket is empty. This is because expiring object versions and cleaning up delete markers are asynchronous steps. For more information, see Understanding object expiration.