Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove multiple S3 buckets at once?

Tags:

amazon-s3

I have a dozen of buckets that I would like to remove in AWS S3, all having a similar name containing bucket-to-remove and with some objects in it.

Using the UI is quite slow, is there a solution to remove all these buckets quickly using the CLI?

like image 242
Armand Grillet Avatar asked Mar 14 '17 08:03

Armand Grillet


People also ask

How do I delete multiple S3 Buckets at once?

To delete multiple S3 objects using a single HTTP request, you can use the AWS CLI, or an AWS SDK. To empty an S3 bucket of its objects, you can use the Amazon S3 console, AWS CLI, lifecycle configuration rule, or AWS SDK.

What is the fastest way to uninstall S3 bucket?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, select the option next to the name of the bucket that you want to delete, and then choose Delete at the top of the page.

What is the best way to delete multiple objects from S3?

Navigate to the Amazon S3 bucket or folder that contains the objects that you want to delete. Select the check box to the left of the names of the objects that you want to delete. Choose Actions and choose Delete from the list of options that appears. Alternatively, choose Delete from the options in the upper right.

How will you delete a bucket that has multiple files and folders in it?

To delete multiple files from an S3 Bucket with the AWS CLI, run the s3 rm command, passing in the exclude and include parameters to filter the files the command is applied to. Let's run the command in test mode first.


1 Answers

You could try this sample line to delete all at once. Remember that this is highly destructive, so I hope you know what you are doing:

for bucket in $(aws s3 ls | awk '{print $3}' | grep my-bucket-pattern); do  aws s3 rb "s3://${bucket}" --force ; done

You are done with that. May take a while depending on the amount of buckets and their content.

like image 143
AndroidMania 2015 Avatar answered Sep 20 '22 12:09

AndroidMania 2015