You can configure lifecycle rules to automatically clear them after a while. Here's a blog post demonstrating how to do this in the console:
https://aws.amazon.com/blogs/aws/s3-lifecycle-management-update-support-for-multipart-uploads-and-delete-markers/
To do this in boto3:
import boto3 s3 = boto3.client('s3') try: lifecycle = s3.get_bucket_lifecycle(Bucket='bucket') except ClientError: lifecycle = {'Rules': []} lifecycle['Rules'].append({ 'ID': 'PruneAbandonedMultipartUploads', 'Status': 'Enabled', 'Prefix': '', 'AbortIncompleteMultipartUpload': { 'DaysAfterInitiation': 7 } }) s3.put_bucket_lifecycle(Bucket='bucket', LifecycleConfiguration=lifecycle)
Adding this configuration to cli would be the same:
$ aws s3api get-bucket-lifecycle --bucket bucket > lifecycle.json
If your bucket does not have a lifecycle policy, get-bucket-lifecycle raises a ClientError value. A robust implementation will provide the correct error.
A policy with only this configuration will look like this:
{ "Rules": [ { "ID": "PruneAbandonedMultipartUpload", "Status": "Enabled", "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 } } ] }
source share