1

I want to have multiple lifecycles for many folders in my bucket.

This seems easy if I use web interface but this should be an automated process so, at least in my case, it must use s3cmd.

It works fine when I use:

s3cmd expire ...

But, somehow, everytime I run this my last lifecycle gets overwrited.

There's an issue on github:

https://github.com/s3tools/s3cmd/issues/863

My question is: is there another way?

Pedro Caldeira
  • 124
  • 2
  • 13
  • 1
    Side-note: These days, it is recommended to use the official [AWS Command-Line Interface (CLI)](http://aws.amazon.com/cli/) rather than `s3cmd`. – John Rotenstein Apr 03 '18 at 08:03

1 Answers1

4

You made me notice I had the exact same problem as you. Another way to access the expire rules with s3cmd is to show the lifecycle configuration of the bucket.

s3cmd getlifecycle s3://bucketname

This way you get some xml formatted text:

<?xml version="1.0" ?>
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
        <Rule>
                <ID>RULEIDENTIFIER</ID>
                <Prefix>PREFIX</Prefix>
                <Status>Enabled</Status>
                <Expiration>
                        <Days>NUMBEROFDAYS</Days>
                </Expiration>
        </Rule>
        <Rule>
                <ID>RULEIDENTIFIER2</ID>
                <Prefix>PREFIX2</Prefix>
                <Status>Enabled</Status>
                <Expiration>
                        <Days>NUMBEROFDAYS2</Days>
                </Expiration>
        </Rule>
</LifecycleConfiguration>

If you put that text in a file, changing the appropriate fields (put identifiers of your choice, set the prefixes you want and the number of days until expiration), you now can use the following command (changing FILE for the path where you put the rules):

s3cmd setlifecycle FILE s3://bucketname

That should work (in my case, now I see several rules when I execute the getlifecycle command, although I do not know yet if the objects actually expire or not).

petemir
  • 167
  • 9