Skip to main content

Applying lifecycle policies

Lifecycle rules automatically clean up buckets: objects are deleted after a defined period, old versions are removed and aborted multipart uploads are cleared. This saves storage costs without the need for manual maintenance.

What lifecycle rules can do

  • Expiration: Delete current objects after X days (or on a specific date)
  • NoncurrentVersionExpiration: Remove outdated versions after X days (for Versioning)
  • ExpiredObjectDeleteMarker: clean up orphaned delete markers
  • AbortIncompleteMultipartUpload: discard stalled multipart uploads after X days
  • Filter: restrict rules to prefixes (e.g. logs/) or tags

Example configuration

lifecycle.json:

{
"Rules": [
{
"ID": "logs-nach-30-tagen-loeschen",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Expiration": { "Days": 30 }
},
{
"ID": "alte-versionen-aufraeumen",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"NoncurrentVersionExpiration": { "NoncurrentDays": 90 },
"Expiration": { "ExpiredObjectDeleteMarker": true }
},
{
"ID": "multipart-reste-verwerfen",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
}
]
}

How to use:

aws s3api put-bucket-lifecycle-configuration --bucket mein-bucket \
--lifecycle-configuration file://lifecycle.json \
--endpoint-url https://s3.internet1.de
Warnung

put-bucket-lifecycle-configuration replaces the entire existing configuration. Before making any changes, export the current configuration and add to it rather than overwriting it.

Check and remove

aws s3api get-bucket-lifecycle-configuration --bucket mein-bucket \
--endpoint-url https://s3.internet1.de

aws s3api delete-bucket-lifecycle --bucket mein-bucket \
--endpoint-url https://s3.internet1.de

Behaviour and subtleties

  • Rules are executed asynchronously (typically once a day); deletion may therefore be delayed.
  • When versioning is enabled, a Expiration initially only creates a delete marker for the current version – the version is only permanently deleted via NoncurrentVersionExpiration.
  • Objects with active Object Lock Retention or Legal Hold are only deleted once the protection period ends.
  • Days counts from the time of the last upload (LastModified), whilst NoncurrentDays counts from the moment a version became out of date.

Typical recipes

ObjectiveRule
Delete temporary files in tmp/ after 1 dayFilter.Prefix = "tmp/", Expiration.Days = 1
Keep the versioned backup bucket leanNoncurrentVersionExpiration.NoncurrentDays = 30 + ExpiredObjectDeleteMarker = true
Avoid costs caused by aborted large uploadsAbortIncompleteMultipartUpload.DaysAfterInitiation = 7 (recommended for every bucket)
Backup software

Do not apply any expiry rules to buckets managed by backup tools (Veeam, Bareos, restic, etc.) – retention in these cases is controlled exclusively by the backup software. The only rule that is harmless and sensible is the multipart clean-up rule.