Last active
August 25, 2021 23:17
-
-
Save acg/a6a0a8b8c65bff647ef104b6ff0b2749 to your computer and use it in GitHub Desktop.
Delete all old object versions in an S3 bucket. Be extremely careful!
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
#!/bin/sh | |
set -e | |
BUCKET="$1" ; shift | |
BATCH_SIZE=100 | |
aws s3api list-object-versions --bucket "$BUCKET" | | |
jq '[.Versions[] | select(.IsLatest == false) | {Key, VersionId}]' | | |
jq -c "_nwise($BATCH_SIZE) | {Objects:., Quiet:false}" | | |
tr '\n' '\0' | | |
xargs -0 -n1 aws s3api delete-objects --bucket "$BUCKET" --delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment