Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save flavono123/f89fcd5defb9c70886cb76113b89fbf0 to your computer and use it in GitHub Desktop.

Select an option

Save flavono123/f89fcd5defb9c70886cb76113b89fbf0 to your computer and use it in GitHub Desktop.
Sum incomplete multipart upload sizes in AWS S3
#!/bin/bash
# ref. https://stackoverflow.com/questions/43192556/using-jq-with-bash-to-run-command-for-each-object-in-array
bucket=$1
aws s3api list-multipart-uploads --bucket "${bucket}" | \
jq -r '.Uploads[] | [.UploadId, .Key] | @tsv' | \
while IFS=$'\t' read -r upload_id key; do
AWS_PAGER="" aws s3api list-parts --bucket "${bucket}" --key "${key}" --upload-id "${upload_id}"
done | \
jq 'select(has("Parts")) | .Parts[].Size' | \
paste -sd+ | bc | numfmt --to=iec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment