Skip to content

Instantly share code, notes, and snippets.

@khaliqgant
Created August 22, 2022 11:26
Show Gist options
  • Save khaliqgant/1f7fc04a614ddca9768da2faf80acb56 to your computer and use it in GitHub Desktop.
Save khaliqgant/1f7fc04a614ddca9768da2faf80acb56 to your computer and use it in GitHub Desktop.
[AWS S3 Delete Directory] Delete Quickly From A S3 Directory #aws #s3
BUCKET_NAME="foo"
DIRECTORY="bar"
aws s3api list-objects-v2 --output text --bucket $BUCKET_NAME --prefix $DIRECTORY --query 'Contents[].[Key]' | pv -l > FILES.keys
tail -n+0 FILES.keys | pv -l | grep -v -e "'" | tr '\n' '\0' | xargs -0 -P4 -n1000 bash -c 'aws s3api delete-objects --bucket $BUCKET_NAME --delete "Objects=[$(printf "{Key=%q}," "$@")],Quiet=true"' _
# https://serverfault.com/questions/679989/most-efficient-way-to-batch-delete-s3-files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment