Last active
May 4, 2021 02:30
-
-
Save petrabarus/5abed92bc487f36bebd8a05ec0d14a73 to your computer and use it in GitHub Desktop.
Batch Empty and Delete S3 Bucket with Grep Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Sometimes we create a lot of S3 Bucket with similar names. | |
# The command below will find all buckets in the region with pattern `bucket_pattern`, | |
# then empty the bucket and then delete the bucket. | |
BUCKET_PATTERN=bucket_pattern | |
aws s3api list-buckets |\ | |
jq -r '.Buckets[].Name' |\ | |
grep $BUCKET_PATTERN |\ | |
xargs -n 1 -I {} sh -c 'aws s3 rm s3://{} --recursive && aws s3 rb s3://{}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Sometimes we create a lot of S3 Bucket with similar names. | |
# The command below will find all buckets in the region with pattern `bucket_pattern`, | |
# then empty the bucket and then delete the bucket. | |
BUCKET_PATTERN=bucket_pattern | |
aws s3api list-buckets |\ | |
jq -r '.Buckets[].Name' |\ | |
grep $BUCKET_PATTERN |\ | |
xargs -n 1 -I {} sh -c 'aws s3 rm s3://{} --recursive' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment