Zum Inhalt springen

S3 Lifecycle Configuration

Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen

A lifecycle configuration is always applied to one specific bucket. It consists of one or more rules (up to 1000 within a single lifecycle configuration).

Each of these rules can include the following elements:

  • ID: Each rule within a lifecycle configuration needs to have a unique ID.
  • Filter: Objects can be filtered by a prefix or by a tag. Filters can also combine both prefix and tags using a logical AND.
  • Expiration: The expiration can be set to a specific date or to a specific time span (number of days) starting with the ingest date of the object.
  • NonCurrentVersionExpiration: Same as Expiration, but only applies to non-current versions.
    If you use versioning on a bucket and delete a file, the file becomes a “non-current version” and a delete marker is inserted as current version. A rule using “nonCurrentVersionExpiration” can be applied to permanently remove these non-current versions from your bucket.
  • Status: The status can be either “Enabled” or “Disabled”. “Disabled” rules are inactive and the actions defined within are not performed.

Note: Please note that when expiration is reached, the respective object is not deleted immediately, but is removed by deletion routines within the next approx. 10 days.

The following rule expires all objects within a bucket which have the prefix “backup/” and were ingested more than 10 days ago:

delete-all-objects-after-ten-days backups/ Enabled 10

To expire all objects within a bucket which have

  • the prefix “backup/”
  • a tag which matches the Key1/Value1
  • and were ingested more then 10 days ago

you can use a lifecycle configuration with two filters combined by a logical AND:

delete-all-backup-objects-key1-value1-after-ten-days backups/ key1 value1 Enabled 10
  1. Create aLifecycle Policy File. This file is in the XML format and could look like this:
my-rule-id my-prefix/ Enabled 99
  1. Use thesetlifecycle <file> <bucket>command to apply the policy to a bucket.
    For thes3://my-example-bucketbucket, the command will look like this:
Terminal window
$ s3cmd setlifecycle lifecycle\_policy.xml s3://my-example-bucket s3://my-example-bucket/: Lifecycle Policy updated
  1. Use thegetlifecycle <bucket>command to retrieve the Lifecycle Policy File for a bucket.
    For thes3://my-example-bucketbucket, the command will look like this:
Terminal window
$ s3cmd getlifecycle s3://my-example-bucket delete-all-objects Enabled 1
  1. Use thedellifecycle <bucket>command to delete the Lifecycle Policy File.
    For thes3://my-example-bucketbucket, the command will look like this:
Terminal window
$ s3cmd dellifecycle s3://my-example-bucket s3://my-example-bucket/: Lifecycle Policy deleted