问题描述
我正在尝试使用 boto3
put_bucket_lifecycle_configuration
设置Amazon S3存储桶中子目录的生命周期配置.我从 aws文档作为参考:
I'm trying to set the lifecycle configuration of a subdirectory in Amazon S3 bucket by using boto3
put_bucket_lifecycle_configuration
. I used this code from aws documentation as referece:
lifecycle_config_settings = {
'Rules': [
{'ID': 'S3 Glacier Transition Rule',
'Filter': {'Prefix': ''},
'Status': 'Enabled',
'Transitions': [
{'Days': 0,
'StorageClass': 'GLACIER'}
]}
]}
我删除了 Transitions
,并添加了 Expiration
,以更好地适应我的目的.这是我的代码:
I removed Transitions
and added Expiration
, to better fit my purpouses. Here is my code:
myDirectory = 'table-data/'
lifecycle_config_settings = {
'Rules': [{
'ID': 'My rule',
'Expiration': {
'Days': 30,
'ExpiredObjectDeleteMarker': True
},
'Filter': {'Prefix': myDirectory},
'Status': 'Enabled'
}
]}
s3 = boto3.client('s3')
s3.put_bucket_lifecycle_configuration(Bucket=myBucket, LifecycleConfiguration=lifecycle_config_settings)
我收到的错误是:
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
什么可能导致此错误?
推荐答案
我遵循了@ Michael-sqlbot的建议,并找到了它不起作用的原因.
I followed @Michael-sqlbot suggestion and found the reason it wasn't working.
此设置中的问题出在 Expiration键
内的'ExpiredObjectDeleteMarker':True
中.在 boto3文档有一个观察结果.
The problem in this settings is in 'ExpiredObjectDeleteMarker': True
that is inside Expiration key
. In boto3 documentation there is an observation about it.
修复后,设置为:
lifecycle_config_settings = {
'Rules': [{
'ID': 'My rule',
'Expiration': {
'Days': 30
},
'Filter': {'Prefix': myDirectory},
'Status': 'Enabled'
}
]}
这篇关于boto3 s3对象到期"MalformedXML"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!