How to Delete Multiple AWS S3 buckets which are in different region
We usually can delete multiple buckets in same region, but S3 is not region centric and sometimes we may need to delete buckets from different regions at same time, So I consider to have below online shell script to help for the same:
Step 1: Place required buckets names to deleted in a file e.g. list.txt, you can get the same using aws s3 ls –output text using AWSCLI
Step 2: You can use below one liner to delete buckets which are mentioned in above file from shell command prompt where you installed AWSCLI for linux.
for i in `cat list.txt`;do j=”$(aws s3api get-bucket-location –bucket $i –output text)”; aws s3 rb s3://$i –region $j –force;done
Above liner explanation:
Shell script related:
Declared 2 variables
i = To store bucket name from file called list.txt
j = region name of the bucket
Usual for loop
AWS related commands:
aws s3api get-bucket-location — will help us to get bucket location(aka region)
aws s3 rb — will help us to delete bucket even though bucket is not
empty with –force option