我正在尝试读取-修改-写入现有的生命周期配置。因此,我最先想到的简单操作是在存储桶之间复制生命周期配置。通过阅读文档,它应该是这样的:
aws s3api get-bucket-lifecycle-configuration --bucket source-backup > \
bucket-lifecycle-configuration.json
这是创建的文件:
[nuevo:~] more bucket-lifecycle-configuration.json
{
"Rules": [
{
"Status": "Enabled",
"Prefix": "",
"NoncurrentVersionExpiration": {
"NoncurrentDays": 180
},
"Expiration": {},
"ID": "DeleteRevisionsOlderThan180Days"
}
]
}
然后将其写入另一个存储桶应该是就像是:
aws s3api put-bucket-lifecycle-configuration --bucket dest-backup \
--cli-input-json file://bucket-lifecycle-configuration.json
或者
aws s3api put-bucket-lifecycle-configuration --bucket dest-backup \
--lifecycle-configuration file://bucket-lifecycle-configuration.json
但第一个会产生错误:
Parameter validation failed:
Unknown parameter in input: "Rules", must be one of: Bucket, LifecycleConfiguration
而第二条命令似乎没有检测到它是 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
任何关于哪里出错的提示。从文档来看放置存储桶生命周期配置这只是一个错误...但话又说回来,我可能只是配置错误或做错了什么?
答案1
第二条命令对我来说很好用
aws s3api put-bucket-lifecycle-configuration --bucket <bucket> --lifecycle-configuration file://<file>
其中 <file> 是使用此命令获取的文件
aws s3api get-bucket-lifecycle-configuration --bucket <bucket-old> ><file>