boto3 s3对象到期"MalformedXML"错误 [英] boto3 s3 Object expiration "MalformedXML" error

查看:111
本文介绍了boto3 s3对象到期"MalformedXML"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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.

'ExpiredObjectDeleteMarker'不能在生命周期到期策略中用天或日期指定.

'ExpiredObjectDeleteMarker' cannot be specified with Days or Date in a Lifecycle Expiration Policy.

修复后,设置为:

lifecycle_config_settings = {
    'Rules': [{
        'ID': 'My rule',
        'Expiration': {
            'Days': 30
        },
        'Filter': {'Prefix': myDirectory},
        'Status': 'Enabled'
     }
]}

这篇关于boto3 s3对象到期"MalformedXML"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆