Manage S3 life cycle configuration
Last updated on
Life cycle configurations automatically expire or delete objects in a bucket based on their age or prefix. Each life cycle configuration applies to one bucket and can contain up to 1000 rules.
Prerequisites
Section titled “Prerequisites”- Object Storage enabled and credentials configured: Enable Object Storage
- AWS CLI installed and configured for STACKIT Object Storage: Set up the AWS CLI
Life cycle rule structure
Section titled “Life cycle rule structure”Each life cycle rule can include:
| Element | Description |
|---|---|
| ID | A unique identifier within the life cycle configuration. |
| Filter | Filters objects by prefix, tag, or both (combined with logical AND). |
| Expiration | Expires objects after a specific date or number of days since upload. |
| NonCurrentVersionExpiration | Same as Expiration, but applies only to non-current versions in versioned buckets. When versioning is enabled and a file is deleted, it becomes a non-current version with a delete marker inserted as the current version. This element permanently removes those non-current versions. |
| Status | Enabled or Disabled. Disabled rules are inactive and no actions are performed. |
Examples
Section titled “Examples”Filter by prefix
Section titled “Filter by prefix”The following rule expires all objects with the prefix backups/ that were uploaded more than 10 days ago:
{ "Rules": [ { "ID": "delete-all-objects-after-ten-days", "Filter": { "Prefix": "backups/" }, "Status": "Enabled", "Expiration": { "Days": 10 } } ]}Combined prefix and tag filter
Section titled “Combined prefix and tag filter”The following rule expires objects with the prefix backups/ and the tag key1=value1 after 10 days:
{ "Rules": [ { "ID": "delete-all-backup-objects-key1-value1-after-ten-days", "Filter": { "And": { "Prefix": "backups/", "Tags": [ { "Key": "key1", "Value": "value1" } ] } }, "Status": "Enabled", "Expiration": { "Days": 10 } } ]}Create a life cycle policy
Section titled “Create a life cycle policy”-
Create a life cycle policy file in JSON format, for example
lifecycle_policy.json:{"Rules": [{"ID": "my-rule-id","Filter": {"Prefix": "my-prefix/"},"Status": "Enabled","Expiration": {"Days": 99}}]} -
Apply the policy to your bucket:
Terminal window aws s3api put-bucket-lifecycle-configuration \--bucket my-example-bucket \--lifecycle-configuration file://lifecycle_policy.json \--endpoint-url https://object.storage.eu01.onstackit.cloud
Get the life cycle policy of a bucket
Section titled “Get the life cycle policy of a bucket”aws s3api get-bucket-lifecycle-configuration \ --bucket my-example-bucket \ --endpoint-url https://object.storage.eu01.onstackit.cloudDelete a life cycle policy
Section titled “Delete a life cycle policy”aws s3api delete-bucket-lifecycle \ --bucket my-example-bucket \ --endpoint-url https://object.storage.eu01.onstackit.cloud