howto abort all incomplete multipart uploads for a bucket
Assuming you have your awscli
all setup and it'll output JSON you can use jq
to project the needed keys with:
BUCKETNAME=<xxx>
aws s3api list-multipart-uploads --bucket $BUCKETNAME \
| jq -r '.Uploads[] | "--key \"\(.Key)\" --upload-id \(.UploadId)"' \
| while read -r line; do
eval "aws s3api abort-multipart-upload --bucket $BUCKETNAME $line";
done
If you are doing multipart uploading, you can do the cleanup form S3 Management console too.
a) Open your S3 bucket
b) Switch to Management Tab
c) Click Add Lifecycle Rule
d) Now type rule name on first step and check the Clean up incomplete multipart uploads checkbox. Now you an type the number of days to keep incomplete parts too.
That's it. You can see these steps in attached screen shot too.
Here is my oneliner, that will abort ALL multipart uploads regardless of status, assuming that you don't have any spaces in your key / filename.
BUCKETNAME=<xxx>;aws s3api list-multipart-uploads --bucket $BUCKETNAME --query 'Uploads[].[Key, UploadId]' --output text | awk '{print "aws s3api abort-multipart-upload --upload-id "$2" --bucket $BUCKETNAME --key " $1 " & wait"}{}' | bash