How to Easily Delete Large S3 Buckets?
Tags: aws, explainlikeimfive
Published: 2018-04-11 13:55:43

---
title: How to Easily Delete Large S3 Buckets?
published: true
description: 
tags: aws, explainlikeimfive
canonical_url: https://blog.totalcloud.io/how-to-easily-delete-large-s3-buckets/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/opael9m8yp00do04sjxl.jpg
---

[Original post](https://blog.totalcloud.io/how-to-easily-delete-large-s3-buckets/)

Deleting an Amazon S3 bucket can be a difficult task. It is even a bigger task if it has a large number of objects in it because you cannot delete non-empty buckets.

Automated solutions such as ‘S3cmd’ or ‘S3nukem’ would either break or take weeks to delete an S3 bucket depending on its size and the number of objects in it.

The best approach is to use AWS, which comes with the benefit of a self-service platform and provides an option of setting lifecycle policy for S3 objects.

AWS lifecycle policies help in defining actions on Amazon S3 during an object’s lifetime. For example, transitioning objects to another storage class, archiving them, or deleting them after a specified period.

Using a shared prefix (that is, objects that have names that begin with a common string), you can define the lifecycle policy for all objects or a subset of objects in the S3 bucket. And using a lifecycle policy, you can define actions specific to current and non-current object versions.

Note: The objects inside the AWS S3 would be gone forever after a day.

This solution is not instant but it takes a day to execute, which is faster than other solutions.

#Here’s How to Set Lifecycle of an S3 Bucket
* Log in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.
* To create a lifecycle policy for a bucket, choose the name of the bucket from the Bucket name list.
![Select bucket](https://thepracticaldev.s3.amazonaws.com/i/708fbm6w6rz5e73wvny6.png)
* Choose the Management tab, and then choose Add lifecycle rule.
![Add lifecycle rule](https://thepracticaldev.s3.amazonaws.com/i/62bdcu940iygw1e29wog.png)
* Give the rule a name and click Next if you want to delete the whole bucket. Also, you can set the lifecycle rule for objects with a specified name prefix (that is, objects with names that begin with a common string), limit the lifecycle rule scope to one or more object tags, and combine a prefix and several tags.
![Name lifecycle rule](https://thepracticaldev.s3.amazonaws.com/i/rtvokj6pemlfenoddvcj.png)
* Click Next on the Transitions tab without any changes.
* Select the options as shown in the image below.
![Set expiration](https://thepracticaldev.s3.amazonaws.com/i/9zx3k9a2eft3ammyqwzz.png)
* Verify the settings for your rule under Review. 
![Verify rule](https://thepracticaldev.s3.amazonaws.com/i/subtitnz65t1qtbfqw4u.png)
* If you need to make changes, choose Previous. Otherwise, click Save.

From now on, AWS does the dirty work for you. S3 will do its own housekeeping, and after a day, everything inside your bucket will be deleted.

This approach can be used if you regularly create stacks with CloudFormation or Terraform, and the buckets won’t delete if there are objects in them.

Instead of writing scripts and adding to the workload you can easily setup lifecycle rules to take action on the AWS S3.

There are a number of things that can be accomplished using lifecycle rules. You can read more about them below.

[Object Lifecycle Management](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)

[How Do I Create a Lifecycle Policy for an S3 Bucket?](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-lifecycle.html)