#!/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'