簡體   English   中英

如何使用基於 Ruby 中的前綴和多個標簽的過濾器更新生命周期配置?

[英]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 ]
          }
        })

配置:

  • 紅寶石 2.6.6
  • aws-sdk-核心 3.109.1
  • aws-sdk-s3 1.103.0

AWS 文檔:S3 用戶指南:生命周期配置示例

要根據鍵前綴一個或多個標簽指定過濾器,您需要將prefix 放在and元素內部and不是外部 然后,Amazon S3 可以組合前綴和標簽過濾器。

這就是它抱怨 XML 格式錯誤的原因。

這應該將生命周期規則應用於鍵前綴為aws_s3_backup_prefixdate-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM