gpt4 book ai didi

amazon-web-services - AWS : Boto3 configuring bucket lifecycle - Malformed XML

转载 作者:行者123 更新时间:2023-12-01 04:34:34 25 4
gpt4 key购买 nike

以下代码应在存储桶/存储桶列表上启用版本控制,然后设置 lifecycle configuration .

import boto3

# Create session
s3 = boto3.resource('s3')
s3Client = boto3.client('s3')

# Bucket list
buckets = ['BUCKETNAMEHERE']

# iterate through list of buckets
for bucket in buckets:
# Enable Versioning
bucketVersioning = s3.BucketVersioning(bucket)
bucketVersioning.enable()

# Configure Lifecycle
s3Client.put_bucket_lifecycle_configuration(
Bucket=bucket,
LifecycleConfiguration={
'Rules': [
{
'Status': 'Enabled',
'NoncurrentVersionTransitions': [
{
'NoncurrentDays': 7,
'StorageClass': 'GLACIER'
},
],
'NoncurrentVersionExpiration': {
'NoncurrentDays': 30
}
},
]
}
)

print "Versioning and lifecycle have been enabled for buckets."

但是,每当我运行它时,我都会收到以下错误:
  File "putVersioning.py", line 42, in <module>
'NoncurrentDays': 30
File "/home/user/.local/lib/python2.7/site-packages/botocore/client.py", line 253, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/user/.local/lib/python2.7/site-packages/botocore/client.py", line 557, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the PutBucketLifecycleConfiguration operation: The XML you provided was not well-formed or did not validate against our published schema

据我所知,一切看起来都正确吗?

最佳答案

根据文档 here您需要添加 Filter 元素,这是 Amazon API 所必需的,但令人困惑的是,boto 不需要。我添加了不推荐使用的 Prefix 参数而不是过滤器,它似乎也有效。

关于amazon-web-services - AWS : Boto3 configuring bucket lifecycle - Malformed XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44159204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com