AWS re:Postを使用することにより、以下に同意したことになります AWS re:Post 利用規約

S3 bucket lifecycle policy through CLI

0

I want to change the storage class of a folder in S3 through the CLI.

I created a lifecycle-policy.json

{
  "Rules": [
    {
      "ID": "Move to Glacier Instant Retrieval",
      "Status": "Enabled",
      "Transitions": [
        {
          "Days": 0,
          "StorageClass": "GLACIER_INSTANT_RETRIEVAL"
        }
      ]
    }
  ]
}

I then ran the following command

aws s3api put-bucket-lifecycle-configuration --bucket backup-glacier-instant-retrieval --lifecycle-configuration file://path-to-file/lifecycle-policy.json

This was the output error

An error occurred (MalformedXML) when calling the PutBucketLifecycleConfiguration operation: The XML you provided was not well-formed or did not validate against our published schema

Any help on what I'm doing wrong?

3回答
1

Hello.

Please change the JSON as below.
"StorageClass" is "GLACIER_IR".
I also think you need to set ""Filter": {}" to apply the rule to the entire bucket.
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/put-bucket-lifecycle-configuration.html

{
    "Rules": [
      {
        "ID": "Move to Glacier Instant Retrieval",
        "Filter": {},
        "Status": "Enabled",
        "Transitions": [
          {
            "Days": 0,
            "StorageClass": "GLACIER_IR"
          }
        ]
      }
    ]
  }
profile picture
エキスパート
回答済み 6ヶ月前
profile picture
エキスパート
レビュー済み 6ヶ月前
profile pictureAWS
エキスパート
レビュー済み 6ヶ月前
  • Using the above JSON, a lifecycle rule will be created as shown below. a

0

I'm not sure if there are other issues, but I can see two. The storage class should be GLACIER_IR instead of GLACIER_INSTANT_RETRIEVAL, and the Days parameter has a minimum value of 1.

エキスパート
回答済み 6ヶ月前
0

Hello, Thanks for detail info on the issue you faced. After a research I came to know that your code has some issue with format or structure. here is the new code in xml format.

<LifecycleConfiguration>
    <Rule>
        <ID>Move to Glacier Instant Retrieval</ID>
        <Status>Enabled</Status>
        <Transition>
            <Days>0</Days>
            <StorageClass>GLACIER_INSTANT_RETRIEVAL</StorageClass>
        </Transition>
    </Rule>
</LifecycleConfiguration>

save this file in your local machine and the following command aws s3api put-bucket-lifecycle-configuration --bucket backup-glacier-instant-retrieval --lifecycle-configuration file://path-to-file/lifecycle-policy.xml If you want to change the storage class of an existing objects use this command aws s3 cp s3://backup-glacier-instant-retrieval/ s3://backup-glacier-instant-retrieval/ --recursive --storage-class GLACIER_INSTANT_RETRIEVAL

Thanks

profile picture
エキスパート
回答済み 6ヶ月前
profile picture
エキスパート
レビュー済み 5ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ