存储桶之间的 AWS CLI put-lifecycle-configuration

存储桶之间的 AWS CLI put-lifecycle-configuration

我有一个存储桶,我为其手动创建了对象生命周期策略;现在我想将该策略应用于其他存储桶。我运行以下命令来获取现有策略:

aws s3api get-bucket-lifecycle --bucket mybucket > s3_lifecyclepolicy.json

生成此文件:

{
    "Rules": [
        {
            "Expiration": {
                "Days": 7
            },
            "ID": "7 Day Expire",
            "Status": "Enabled",
            "NoncurrentVersionExpiration": {
                "NoncurrentDays": 14
            }
        }
    ]
}

然后我尝试像这样运行应用该策略:

aws s3api put-bucket-lifecycle-configuration --bucket anotherbucket --lifecycle-configuration file://s3_lifecyclepolicy.json

但出现此错误:

A client error (MalformedXML) occurred when calling the 
PutBucketLifecycleConfiguration
operation: The XML you provided was not well-formed or did not 
validate against
our published schema

我尝试修改 json,但 cli 会报错,提示语法错误,所以 json 应该是正确的,但我不确定 XML 相关错误来自哪里。有什么建议吗?

答案1

看起来这Prefix是一个必需参数,即使它没有显示在get-bucket-lifecycle输出中。

此版本有效:

{
  "Rules": [
    {
      "Expiration": {
        "Days": 7
      },
      "ID": "7 Day Expire",
      "Prefix": "",
      "Status": "Enabled",
      "NoncurrentVersionExpiration": {
        "NoncurrentDays": 14
      }
    }
  ]
}

相关内容