Created
August 22, 2022 11:26
-
-
Save khaliqgant/1f7fc04a614ddca9768da2faf80acb56 to your computer and use it in GitHub Desktop.
[AWS S3 Delete Directory] Delete Quickly From A S3 Directory #aws #s3
This file contains hidden or 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
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