aws cli put-bucket-lifecycle-configuration MalformedXML

Lifecycle configuration:

{
  "Rules": [
    {
      "ID": "ArchiveRule",
      "Status": "Enabled",
      "Transitions": [
        {
          "Days": 90,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 180,
          "StorageClass": "GLACIER"
        }
      ]
    }
  ]
}

Command:

aws s3api put-bucket-lifecycle-configuration --bucket $bucket --lifecycle-configuration file://lifecycle.json

Output:

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
exit status 255

Solution:

It turns out the Filter element is necessary as described in http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTlifecycle.html

 

New lifecycle configuration:

{
  "Rules": [
    {
      "ID": "ArchiveRule",
      "Status": "Enabled",
      "Filter": {
        "Prefix": ""
      },
      "Transitions": [
        {
          "Days": 90,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 180,
          "StorageClass": "GLACIER"
        }
      ]
    }
  ]
}
Advertisements