Bucket Lifecycle Configuration

In order to manage the lifecycle of certain objects within a S3 bucket, SWITCHengines supports to enable expiration policies. This is especially useful for objects which shall be available only for a certain time range as it is usually the case for logging or backup data.

Only one lifecycle policy applies per bucket which might contain multiple rules for different prefixes.
Note: Prefix does not contain the bucket name.

The following example enables an expiration rule to the prefix/subfolder log/

<LifecycleConfiguration>
  <Rule>
     <ID>7-days-log-expiration</ID>
     <Prefix>log/</Prefix>
     <Status>Enabled</Status>
     <Expiration>
        <Days>7</Days>
     </Expiration>
  </Rule>
</LifecycleConfiguration>

It is to mention that the expiration value needs to be specified in days where the value has to be an integer. This rule can be set to the bucket as follows:

s3cmd setlifecycle log-expiration.xml s3://BUCKET

If the bucket has the structure:

BUCKET/
     foo.bkp
     foo1.log
     backup/
          backup/foo.bkp
          backup/bar.bkp
     log/
          log/foo2.log

The above expiration rule would lead to an expiration of the object 's3://BUCKET/log/foo2.log' 7 days after its creation date. The other objects do not match the prefix and will therefore remain within the bucket.

IMPORTANT: If a bucket lifecycle should be updated, one first needs to delete the old configuration.

The current lifecycle can be deleted using the following request

s3cmd dellifecycle s3://BUCKET

The current lifecycle configuration can be retrieved using the following request

s3cmd getlifecycle s3://BUCKET

It is also possible to specify multiple rules as the following example shows:

<LifecycleConfiguration>
    <Rule>
        <ID>7-days-log-expiration</ID>
        <Prefix>log/</Prefix>
        <Status>Enabled</Status>
        <Expiration>
            <Days>7</Days>
        </Expiration>
    </Rule>
    <Rule>
        <ID>14-days-backup-expiration</ID>
        <Prefix>backup/</Prefix>
        <Status>Enabled</Status>
        <Expiration>
            <Days>14</Days>
        </Expiration>
    </Rule>
</LifecycleConfiguration>

This configuration would enforce an expiration of:

  • 's3://BUCKET/backup/foo.bkp' and 's3://BUCKET/backup/bar.bkp' after 14 days
  • 's3://BUCKET/log/foo.log' after 7 days