Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto abort all incomplete multipart uploads for a bucket

Tags:

Sometimes multipart uploads hang or don't complete for some reason. In that case you are stuck with orphaned parts that are tricky to remove. You can list them with:

aws s3api list-multipart-uploads --bucket $BUCKETNAME 

I am looking for way to abort them all.

like image 716
Refael Ackermann Avatar asked Sep 12 '16 19:09

Refael Ackermann


People also ask

How do I clean up incomplete multipart uploads?

Under Delete expired delete markers or incomplete multipart uploads, select Delete incomplete multipart uploads. Then, enter the number of days after the multipart upload initiation that you want to end and clean up incomplete multipart uploads. Select Create rule.

How do I stop accidental deletion S3 bucket?

To prevent or mitigate future accidental deletions, consider the following features: Enable versioning to keep historical versions of an object. Enable Cross-Region Replication of objects. Enable MFA delete to require multi-factor authentication (MFA) when deleting an object version.

How do you protect buckets content from unauthorized usage?

The easiest way to secure your bucket is by using the AWS Management Console. First select a bucket and click the Properties option within the Actions drop down box. Now select the Permissions tab of the Properties panel. Verify that there is no grant for Everyone or Authenticated Users.

Does S3 console use multipart upload?

Amazon S3 is excited to announce Multipart Upload which allows faster, more flexible uploads into Amazon S3. Multipart Upload allows you to upload a single object as a set of parts. After all parts of your object are uploaded, Amazon S3 then presents the data as a single object.


1 Answers

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 
like image 105
Refael Ackermann Avatar answered Sep 21 '22 16:09

Refael Ackermann