[英]How can I update a lifecycle configuration with a filter based on both prefix and multiple tags in Ruby?
我想將一個生命周期配置放到一個 S3 存儲桶中,該規則使用帶有多個標簽和前綴的過濾器。
我可以成功put_lifecycle_configuration
如果過濾器僅使用一個標簽或一個前綴,但我得到一個Aws::S3::Errors::MalformedXML (The XML you provided was not well-formed or did not validate against our published schema)
從響應AWS 如果我嘗試使用and:
來組合多個標簽或標簽和前綴。
(編輯:將prefix:...
放入and:
按照下面Ermiya 的回答散列)
我究竟做錯了什么?
這是我的規則:
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 ]
}
})
配置:
要根據鍵前綴和一個或多個標簽指定過濾器,您需要將prefix
放在and
元素內部, and
不是外部。 然后,Amazon S3 可以組合前綴和標簽過濾器。
這就是它抱怨 XML 格式錯誤的原因。
這應該將生命周期規則應用於鍵前綴為aws_s3_backup_prefix
、 date-month-day
標記值為 1 和date-month-num
標記值為 1 的對象:
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-SDK核心3.109.1,這是固定在AWS-SDK核心3.109.2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.