使用aws或boto删除Amazon S3多个对象

时间:2015-03-19 13:13:00

标签: python amazon-web-services boto

我想尝试使用亚马逊功能delete multiple object boto或aws。

如何使用boto或aws启动POST请求? 以下是我想尝试的内容:

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>           

干杯

1 个答案:

答案 0 :(得分:5)

Boto为MultiDelete提供支持。以下是您将如何使用它的示例:

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)

结果将提供有关哪些删除操作成功以及哪些删除操作失败的信息。如果您希望Quiet模式仅告诉您失败,请将quiet=True传递给delete_keys来电。