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.

How to Easily Delete Large S3 Buckets?
  • Choose the Management tab, and then choose Add lifecycle rule.

How to Easily Delete Large S3 Buckets?

  • 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.

How to Easily Delete Large S3 Buckets?

  • Click Next on the Transitions tab without any changes.
  • Select the options as shown in the image below.

How to Easily Delete Large S3 Buckets?

  • Verify the settings for your rule under Review.
  • If you need to make changes, choose Previous. Otherwise, click Save.

How to Easily Delete Large S3 Buckets?

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

How Do I Create a Lifecycle Policy for an S3 Bucket?

Learn how lifecycle policies can help with cost optimization here

How To Easily Delete Large S3 Buckets?

Smart Scheduling at your fingertips

Go from simple to smart, real-time AWS resource scheduling to save cost and increase team productivity.

Learn More
More Posts

You Might Also Like

Cloud Automation
New In: No-code cloud management workflows for Azure, VMware & Private Cloud (in addition to AWS)
At TotalCloud, we’ve been enabling workflow-based cloud management for AWS to make it intuitive, accelerated, and no-code. Instead of programming cloud management use cases or depending on siloed solutions, we built out a platform that gives you building blocks to assemble any cloud management solution. 
September 4, 2020
Sayonee
Cloud Computing
List of Essential Kubernetes Tools
Kubernetes is a Container-as-a-Service with tons of unique tools to choose from. External tools play a role in integrating with different systems or maintaining control over the clusters you deploy. Manual health checks and troubleshooting is not ideal to keep a system in full health.This list of tools will provide ample support to your containers and have enough configuration to leave management flexible...
August 12, 2020
Hrishikesh
AWS Use Case Files
TotalCloud Inventory Actions: Giving a new meaning to Cloud Inventory
Learn how the TotalCloud Inventory Dashboard can become equivalent to your cloud provider’s SDK. Carry out any action on any discovered resource with Inventory Actions.
July 30, 2020
Sayonee
AWS Tips & Tricks
AWS Tutorial: Create an AWS Instance Scheduler with Terraform
Terraform is a popular IaaS tool used by many to create, update, and maintain their AWS architecture. If you use Terraform to provision your AWS architecture, you won’t be disappointed with our new AWS tutorial video.We provide you with the means to set up your own instance scheduler from Terraform...
July 20, 2020
Hrishikesh
Cloud Computing
Azure vs AWS: What you need to know
Companies that have jumped the gun with cloud migration during this time of crisis have committed a fatal mistake. The knowledge gap among businesses that seek to migrate is often underestimated, leading to devastating expenditures and operational inefficiencies...
July 15, 2020
Hrishikesh
AWS Use Case Files
Automating Auto Scaling Group Updates
AWS introduced autoscaling to make EC2 cluster scaling easier. We've seen users constantly make changes to their EC2s and put new policies into play. It’s important to update your Autoscaling group with the new instances so that it doesn’t ignore these machines.
July 6, 2020
Hrishikesh