1

I am trying to read-modify-write an existing life-cycle configuration. So the simpler thing I am staring out with is copying a life-cycle configuration between buckets. From reading through the documentation it should be something like:

aws s3api get-bucket-lifecycle-configuration --bucket source-backup > \
   bucket-lifecycle-configuration.json

Here is the file created:

[nuevo:~] more bucket-lifecycle-configuration.json
{
    "Rules": [
        {
            "Status": "Enabled", 
            "Prefix": "", 
            "NoncurrentVersionExpiration": {
                "NoncurrentDays": 180
            }, 
            "Expiration": {}, 
            "ID": "DeleteRevisionsOlderThan180Days"
        }
    ]
}

Then to write this to another bucket it should be something like:

aws s3api put-bucket-lifecycle-configuration --bucket dest-backup \
   --cli-input-json file://bucket-lifecycle-configuration.json

or

aws s3api put-bucket-lifecycle-configuration --bucket dest-backup \
   --lifecycle-configuration file://bucket-lifecycle-configuration.json

But the first yields the error:

Parameter validation failed:
Unknown parameter in input: "Rules", must be one of: Bucket, LifecycleConfiguration

And the second command doesn't seem to detect it is json since it yields:

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

Any hints on what is going wrong. It looks like from the documentation on put-bucket-lifecycle-configuration that this is simply an error... but then again I might just have something mis-configured or be doing something wrong?

sysjas
  • 193
  • 2
  • 4
  • 16
  • If `aws s3api put-bucket-lifecycle-configuration --generate-cli-skeleton` is supported here, that should make the solution obvious. You can't directly use the output as input -- the output will most likely need to be modified to add some kind of outer wrapper like `{ LifecycleConfiguration:` ... `}`. – Michael - sqlbot Mar 20 '16 at 17:18
  • Wow! On the surface of it, that is pretty bad design! Maybe there is some deep reason why this is not possible?, but it would appear not being able to use the result of a get as input for a put, is well... not a good design... – sysjas Mar 21 '16 at 20:02
  • Note, I should have said a wrapper like `{"Lifecycle Configuration":` ... `}` since JSON object keys need to be quoted. If they had made input and output compatible, that could be tedious for other kinds of operations, I suppose. If I ask for the "foo" I don't necessarily need the response wrapped it in an object with a single key called "foo" because I'd just have to unwrap it before use... and I do find such redundancy tedious when it's there. Speculation. – Michael - sqlbot Mar 21 '16 at 21:09
  • Did you try this, by the way? I was speculating, above, based on the error and experience using aws-cli with a different service. If so, consider posting an answer for the benefit of future visitors. Answering your own question is fine here when the question is genuine and the answer represents your own work to solve the problem (but not so much if you cull the good stuff out of someone else's posted answer to your question; my comments are not an answer, so please feel free). – Michael - sqlbot Mar 21 '16 at 21:13
  • Actually, I have to confess I didn't try this... I suppose I should, In the end I only had 5 buckets so I *shudder* did it by hand by clicking through. I always like to be able to automate these things whenever I can, making it less error prone, more repeatable etc etc... Ohh well. Next time... – sysjas Mar 26 '16 at 10:43

1 Answers1

1

Second command worked fine for me

aws s3api put-bucket-lifecycle-configuration --bucket <bucket> --lifecycle-configuration file://<file>

Where <file> is the file obtained with this command

aws s3api get-bucket-lifecycle-configuration --bucket <bucket-old> ><file>
JLSM
  • 11
  • 1