【问题标题】:Boto3 S3 client.put_bucket_logging() Broken?Boto3 S3 client.put_bucket_logging() 坏了?
【发布时间】:2018-07-06 06:43:00
【问题描述】:

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

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

Amazon's documentation 关于 MalformedXML 错误表示:

当用户发送格式错误的 xml(不 符合已发布的 xsd) 的配置。错误信息 是,“您提供的 XML 格式不正确或未经验证 反对我们发布的架构。”

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

编辑:[已编辑] 答:下面

【问题讨论】:

  • 您能否展示一下您实际拨打电话的方式?你在传递什么?
  • @gamaat... 对此感到抱歉。刚刚将脚本添加到问题中。
  • API 文档 (docs.aws.amazon.com/AmazonS3/latest/API/…) 似乎建议,如果您使用的是 CanonicalUser 类型,则必须包含 ID 以及 DisplayName。

标签: python debugging amazon-s3 boto3


【解决方案1】:

经过进一步调查,client.create_bucket() 方法的 Boto3 documentation 似乎缺少“ACL”参数的一些关键选项。具体来说,它是缺失的:

ACL='log-delivery-write'

幸运的是,full set of options 可以在 @garnaat 提供的 AWS 文档的链接中找到。谢谢你的指点。

在为日志存储桶实施此选项后,我可以使用 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)

希望有特权的人在某个时候有机会调整 S3 的 boto3 文档。在有关Amazon's three pre-defined groups 的文档中提个醒也很好,因为有很多方法可以授予组权限。

【讨论】:

    【解决方案2】:

    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 中的要求列出它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多