I want to put a lifecycle_configuration to an S3 bucket with a rule that uses a filter with multiple tags and a prefix.
I can successfully put_lifecycle_configuration
if the filter uses only one tag or one prefix, but I get a Aws::S3::Errors::MalformedXML (The XML you provided was not well-formed or did not validate against our published schema)
response from AWS if I try to use an and:
to combine multiple tags or a tag and a prefix.
(edit: put the prefix:...
within the and:
Hash per Ermiya's answer below)
What am I doing wrong?
Here is my rule:
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
}
}
And here is how I use it to put the lifecycle configuration:
# 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 ]
}
})
Config:
AWS Documentation: S3 User Guide: Examples of lifecycle configuration
This bug was fixed in the very next version. I was using aws-sdk-core 3.109.1 and this was fixed in aws-sdk-core 3.109.2