Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 multiple object delete using aws or boto

I would like to try amazone feature delete multiple object but using boto or aws.

How can I lanuch a POST request using boto or aws ?? Below is the stuff I wanna try :

POST /?delete HTTP/1.1
Host: bucketname.s3.amazonaws.com
Authorization: authorization string
Content-Length: Size
Content-MD5: MD5

<?xml version="1.0" encoding="UTF-8"?>
<Delete>
    <Quiet>true</Quiet>
    <Object>
         <Key>Key</Key>
         <VersionId>VersionId</VersionId>
    </Object>
    <Object>
         <Key>Key</Key>
    </Object>
    ...
</Delete>           

Cheers

like image 573
user2563547 Avatar asked Mar 19 '15 13:03

user2563547


People also ask

How do I Delete files from my S3 Boto?

You can delete the file from S3 bucket by using object. delete().

How do I Delete multiple S3 buckets at once?

To delete multiple S3 objects using a single HTTP request, you can use the AWS CLI, or an AWS SDK. To empty an S3 bucket of its objects, you can use the Amazon S3 console, AWS CLI, lifecycle configuration rule, or AWS SDK.

What is the best way to delete multiple objects from S3?

Navigate to the Amazon S3 bucket or folder that contains the objects that you want to delete. Select the check box to the left of the names of the objects that you want to delete. Choose Actions and choose Delete from the list of options that appears. Alternatively, choose Delete from the options in the upper right.

What is the fastest way to delete S3 buckets?

To delete an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, select the option next to the name of the bucket that you want to delete, and then choose Delete at the top of the page.


1 Answers

Boto provides support for MultiDelete. Here's an example of how you would use it:

import boto.s3
conn = boto.s3.connect_to_region('us-east-1')  # or whatever region you want
bucket = conn.get_bucket('mybucket')
keys_to_delete = ['mykey1', 'mykey2', 'mykey3', 'mykey4']
result = bucket.delete_keys(keys_to_delete)

The result will provide information about which delete operations were successful and which, if any, failed. If you want the Quiet mode which tells you only about failures, pass in quiet=True to the delete_keys call.

like image 56
garnaat Avatar answered Sep 27 '22 16:09

garnaat