编程语言
首页 > 编程语言> > python-演示如何使用boto3从S3存储桶中删除一个或多个特定键

python-演示如何使用boto3从S3存储桶中删除一个或多个特定键

作者:互联网

boto3 function允许从S3存储桶中删除密钥列表.请您举例说明如何使用它:

>一个要删除的密钥.
>要删除的多个键的列表.

谢谢

delete_objects(**kwargs)
This operation enables you to delete multiple objects from a bucket using a  single HTTP request. You may specify up to 1000 keys.

Request Syntax

response = bucket.delete_objects(
    Delete={
        'Objects': [
            {
                'Key': 'string',
                'VersionId': 'string'
            },
        ],
        'Quiet': True|False
    },
    MFA='string',
    RequestPayer='requester'
)

解决方法:

删除一个对象:

response = bucket.delete_objects(
    Delete={
        'Objects': [
            {
                'Key': 'myObjectKey'
            }
        ]
    }
)

删除两个对象:

response = bucket.delete_objects(
    Delete={
        'Objects': [
            {
                'Key': 'myFirstObjectKey'
            },
            {
                'Key': 'mySecondObjectKey'
            }
        ]
    }
)

我觉得文档(您链接到的文档)使这一点非常明显.我对您如何使文档感到困惑感到好奇.

标签:amazon-web-services,amazon-s3,boto3,python
来源: https://codeday.me/bug/20191026/1939137.html