Skip to content

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.

Each life cycle rule can include:

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
}
}
]
}

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
}
}
]
}
  1. 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
    }
    }
    ]
    }
  2. 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
Terminal window
aws s3api get-bucket-lifecycle-configuration \
--bucket my-example-bucket \
--endpoint-url https://object.storage.eu01.onstackit.cloud
Terminal window
aws s3api delete-bucket-lifecycle \
--bucket my-example-bucket \
--endpoint-url https://object.storage.eu01.onstackit.cloud