Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfolkens/a8c9f66c60782923d54372af818f543e to your computer and use it in GitHub Desktop.
Save bfolkens/a8c9f66c60782923d54372af818f543e to your computer and use it in GitHub Desktop.
Abort all orphaned multipart upload fragments for a bucket.
#!/bin/bash
# Usage
# ./abort-all-orphaned-multipart-uploads.sh [profile]
#
# Requirements
# jq
# awscli
profile=$1
aws s3 ls --profile $profile | \
cut -f 3 -d ' ' | \
while read bucket; do
echo "Listing upload fragments in $bucket"
aws s3api list-multipart-uploads --profile $profile --bucket $bucket | \
jq -r '.Uploads[] | "--key \"\(.Key)\" --upload-id \(.UploadId)"' | while read -r line; do
echo " abort-multipart-upload $line"
eval "aws s3api abort-multipart-upload --profile $profile --bucket $bucket $line"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment