Question:
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 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
POST /?delete HTTP/1.1 Host: bucketname.s3.amazonaws.com Authorization: authorization string Content-Length: Size Content-MD5: MD5 ... |
Cheers
Answer:
Boto provides support for MultiDelete. Here’s an example of how you would use it:
1 2 3 4 5 6 |
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.