我想将生命周期配置放入 S3 存储桶,其规则使用具有多个标签和前缀的过滤器。
put_lifecycle_configuration
如果过滤器只使用一个标签或一个前缀,我可以成功,但Aws::S3::Errors::MalformedXML (The XML you provided was not well-formed or did not validate against our published schema)
如果我尝试使用 anand:
来组合多个标签或一个标签和一个前缀,我会收到来自 AWS 的响应。
(编辑:根据Ermiya 的回答prefix:...
将and:
Hash放在下面)
我究竟做错了什么?
这是我的规则:
aws_s3_backup_prefix = "production_backup" # this is fetched from ENV in real life
rule_expire_yearly_after_10y = {
id: "Expire 1 January backups after 10 years",
filter: {
and: {
prefix: aws_s3_backup_prefix,
tags: [
{ key: 'date-month-day', value: '1'},
{ key: 'date-month-num', value: '1'}
]
}
},
status: 'Enabled',
expiration: {
days: 3650
}
}
以下是我如何使用它来放置生命周期配置:
# aws_client is a valid Aws::S3::Client
# I have access to aws_s3_backup_bucket_name
# I can get and put a simple lifecycle_configuration (no 'and:') with this client and bucket
aws_client.put_bucket_lifecycle_configuration({
bucket: aws_s3_backup_bucket_name,
lifecycle_configuration: {
rules: [ rule_expire_yearly_after_10y ]
}
})
配置:
- 红宝石 2.6.6
- aws-sdk-core 3.109.1
- aws-sdk-s3 1.103.0