3

I have a bucket that I manually created an object lifecycle policy for; now I'd like to apply that policy to other buckets. I run the following command to get the existing policy:

aws s3api get-bucket-lifecycle --bucket mybucket > s3_lifecyclepolicy.json

Which generates this file:

{
    "Rules": [
        {
            "Expiration": {
                "Days": 7
            },
            "ID": "7 Day Expire",
            "Status": "Enabled",
            "NoncurrentVersionExpiration": {
                "NoncurrentDays": 14
            }
        }
    ]
}

I then try to run apply the policy like so:

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

But get this error:

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

I've tried modifying the json, and the cli will error out with a syntax error, so the json should be correct, but I'm not sure where the XML related error is coming from. Any suggestions?

gsoyka
  • 31
  • 3

1 Answers1

4

It appears that Prefix is a required parameter, even though it did not display in the get-bucket-lifecycle output.

This version works:

{
  "Rules": [
    {
      "Expiration": {
        "Days": 7
      },
      "ID": "7 Day Expire",
      "Prefix": "",
      "Status": "Enabled",
      "NoncurrentVersionExpiration": {
        "NoncurrentDays": 14
      }
    }
  ]
}
John Rotenstein
  • 871
  • 7
  • 16