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'
            }
        ]
    }
)

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

上一篇:我如何使用AWS Lambda通过创建临时文件将“文件”上传到S3?


下一篇:[AWS Devops]CodeBuild ----buildspec.yaml