3

当我在 boto3 中调用client.put_bucket_logging() 方法以定义最近创建的存储桶的日志文件的位置时,我收到以下错误:

botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the 
PutBucketLogging operation: The XML you provided was not well-formed or did not 
validate against our published schema

亚马逊关于 MalformedXML 错误的文档表明:

当用户为配置发送格式错误的 xml(不符合已发布的 xsd 的 xml)时,就会发生这种情况。错误消息是“您提供的 XML 格式不正确或未针对我们发布的模式进行验证。”

此方法的文档相当精简,但确实存在的文档没有提及将 xml 传递到参数中的任何内容。所以,我开始相信这可能是 boto3 的问题,而不是我传递给它的参数。我已尝试进行调整以解决此问题(仅减少到所需的参数)并仔细检查了我的语法,但找不到解决方案。还有其他人遇到这个问题吗?

编辑:[已编辑] 答案:以下

4

2 回答 2

2

After further investigation, it appears that the Boto3 documentation for client.create_bucket() method is missing some key options for the 'ACL' parameter. Specifically, it is missing:

ACL='log-delivery-write'

Luckily, the full set of options can be found in a link off the AWS Documentation that @garnaat provided. Thanks for that pointer.

Once I implemented this option for the log bucket, I was able to enable logging for the example bucket using client.put_bucket_logging()

kw_args = {
'Bucket': 'example-log-bucket,
    'ACL': 'log-delivery-write'
}
client.create_bucket(**kw_args)

kw_args = {
    'Bucket': 'example-user-bucket,
    'ACL': 'private'
}
client.create_bucket(**kw_args)

kw_args = {
    'Bucket': 'example-user-bucket,
    'BucketLoggingStatus': {
        'LoggingEnabled': {
            'TargetBucket': 'example-log-bucket',
            'TargetPrefix': 'user/'
        }
    }
}
client.put_bucket_logging(**kw_args)

Hopefully someone with privileges will get a chance to adjust the boto3 documentation for S3 at some point. It would also be nice to have a heads up in the documentation about Amazon's three pre-defined groups, since there are a lot of methods which grant permissions to groups.

于 2015-09-11T19:00:21.253 回答
1

根据https://github.com/boto/boto3/issues/180 --

您还可以使用:

s3c.put_bucket_acl(
    AccessControlPolicy = {
        "Owner": {
            "ID": "canonical_user_id_sdakfjldsakjf" # see https://docs.aws.amazon.com/general/latest/gr/acct-identifiers.html
        },
        'Grants': [
            {
                'Grantee': {
                    'Type': 'Group',
                    'URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'
                },
                'Permission': 'WRITE'
            },
            {
                'Grantee': {
                    'Type': 'Group',
                    'URI': 'http://acs.amazonaws.com/groups/s3/LogDelivery'
                },
                'Permission': 'READ_ACP'
            }
        ]
    },
    Bucket=bucket
)

注意 Owner 是必需的,否则您将收到 MalformedXML 错误,即使文档当前未按 put_bucket_acl中的要求列出它

于 2018-07-05T22:43:00.903 回答