首页 > 解决方案 > Python Boto3 PutBucketReplication 操作:您提供的 XML 格式不正确或未针对我们发布的架构进行验证

问题描述

我正在尝试使用 python boto3 更新存储桶的复制规则。但我不断收到错误:botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the PutBucketReplication operation: The XML you provided was not well-formed or did not validate against our published schema

我正在按照此处的文档执行此操作:https ://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_replication

这是我正在运行的函数。谁能看到我传递的 xml 有什么问题?

def apply_bucket_replication_rule(client):
    response = client.put_bucket_replication(
        Bucket= 'my-bucket',
            'Role': 'arn:aws:iam::0123456:role/replicate_s3_buckets',
            'Rules': [
                {
                    'Status': 'Enabled',
                    'Destination': {
                        'Bucket': 'arn:aws:s3:::my-bucket-backup',
                        'Account': '111222333'
                    }
                }
            ]
        },
    )
    print (response)

标签: pythonamazon-web-servicesamazon-s3boto3boto

解决方案


我遇到了同样的问题,按照 (stackoverflow.com/a/57778885/9931092) 的回答为我工作,这是我的工作代码示例:

def apply_bucket_replication_rule(client):
response = client.put_bucket_replication(
    Bucket='mybucket',
    ReplicationConfiguration={
        'Role': 'arn:aws:iam::0123456:role/replicate_s3_buckets',
        'Rules': [
            {
                "Status": "Disabled",
                "Priority": 1,
                "DeleteMarkerReplication": {"Status": "Disabled"},
                "Filter": {"Prefix": ""},
                "Destination": {
                    "Bucket": "arn:aws:s3:::my-bucket-backup",
                    "Account": "111222333"
                }
            }
        ]
    }
)
print(response)

推荐阅读