S3 Lifecycle Configuration
Structure of Lifecycle Configurations
Section titled “Structure of Lifecycle Configurations”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.
Examples
Section titled “Examples”Simple filtering by prefix
Section titled “Simple filtering by prefix”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 10Combined filters
Section titled “Combined filters”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 10Create a lifecycle policy
Section titled “Create a lifecycle policy”- Create aLifecycle Policy File. This file is in the XML format and could look like this:
my-rule-id my-prefix/ Enabled 99- Use the
setlifecycle <file> <bucket>command to apply the policy to a bucket.
For thes3://my-example-bucketbucket, the command will look like this:
$ s3cmd setlifecycle lifecycle\_policy.xml s3://my-example-bucket s3://my-example-bucket/: Lifecycle Policy updatedGet the lifecycle policy of a bucket
Section titled “Get the lifecycle policy of a bucket”- Use the
getlifecycle <bucket>command to retrieve the Lifecycle Policy File for a bucket.
For thes3://my-example-bucketbucket, the command will look like this:
$ s3cmd getlifecycle s3://my-example-bucket delete-all-objects Enabled 1Delete a lifecycle policy
Section titled “Delete a lifecycle policy”- Use the
dellifecycle <bucket>command to delete the Lifecycle Policy File.
For thes3://my-example-bucketbucket, the command will look like this:
$ s3cmd dellifecycle s3://my-example-bucket s3://my-example-bucket/: Lifecycle Policy deleted