Docs

Lifecycle rules

Lifecycle rules clean up a bucket automatically. You define once what is deleted after how many days, and chili carries it out in the background. This keeps used storage, and with it your costs, under control without running your own deletion scripts.

A lifecycle configuration applies per bucket and contains one or more rules. You set it up through the S3 API, for example with the AWS CLI.

What a rule can do

Action

S3 element

Effect

Expire objects

Expiration with Days or Date

deletes current objects after a number of days or from a date; with versioning, chili sets a delete marker

Delete noncurrent versions

NoncurrentVersionExpiration with NoncurrentDays

deletes versions permanently once they have been noncurrent for that many days

Remove orphaned delete markers

Expiration with ExpiredObjectDeleteMarker

removes delete markers that no longer have any version behind them

Abort incomplete uploads

AbortIncompleteMultipartUpload with DaysAfterInitiation

frees storage used by abandoned multipart uploads

A Filter limits a rule to a prefix (for example logs/) or to objects with a specific tag. Without a filter, the rule applies to the whole bucket.

What lifecycle rules do not do on chili

  • No transitions to other storage classes: chili is hot storage. All data sits in the same class and can be read immediately. Rules with Transition to classes such as Glacier do not exist on chili.
  • No deletion of locked versions: versions with a running Object Lock period or a legal hold are kept until the lock expires or is removed. Plan capacity for the full period.

When lifecycle rules pay off

  • Buckets with versioning: without a rule, noncurrent versions are kept and billed forever. A rule such as "delete noncurrent versions after 30 days" limits the growth. See Versioning.
  • Logs and temporary data: exports, logs or intermediate results that are worthless after a fixed time.
  • Uploads of large files: when a multipart upload is abandoned, the parts already uploaded use storage without showing up in listings. A rule with AbortIncompleteMultipartUpload cleans them up.

When not to set lifecycle rules

  • Buckets used by backup software: Veeam and other backup programs manage retention themselves. Lifecycle rules on a Veeam bucket are not supported and can cause backup or restore errors. See Veeam (SOBR).
  • Data whose retention an application controls: if the application deletes according to its own rules, do not add a second, conflicting rule on the bucket.

Example: configuration with the AWS CLI

This configuration contains three rules:

  • Objects under logs/ are deleted after 90 days.
  • Noncurrent versions in the whole bucket are deleted 30 days after they were replaced; orphaned delete markers are removed.
  • Incomplete multipart uploads are aborted after 7 days.

Save the configuration as lifecycle.json:

{
  "Rules": [
    {
      "ID": "logs-90-days",
      "Filter": { "Prefix": "logs/" },
      "Status": "Enabled",
      "Expiration": { "Days": 90 }
    },
    {
      "ID": "noncurrent-versions-30-days",
      "Filter": { "Prefix": "" },
      "Status": "Enabled",
      "NoncurrentVersionExpiration": { "NoncurrentDays": 30 },
      "Expiration": { "ExpiredObjectDeleteMarker": true }
    },
    {
      "ID": "multipart-cleanup",
      "Filter": { "Prefix": "" },
      "Status": "Enabled",
      "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
    }
  ]
}

Apply the configuration. It replaces any existing lifecycle configuration completely:

aws s3api put-bucket-lifecycle-configuration \
  --bucket my-bucket \
  --lifecycle-configuration file://lifecycle.json \
  --endpoint-url https://s3-ch-east.chilistorage.com

Check the configuration:

aws s3api get-bucket-lifecycle-configuration \
  --bucket my-bucket \
  --endpoint-url https://s3-ch-east.chilistorage.com

Remove all rules:

aws s3api delete-bucket-lifecycle \
  --bucket my-bucket \
  --endpoint-url https://s3-ch-east.chilistorage.com

The access keys need permission to read and set the lifecycle configuration (s3:GetLifecycleConfiguration, s3:PutLifecycleConfiguration). Give this permission to administrators only, not to your applications' keys. See Access control.

Common pitfalls

  • Rule deletes more than expected: a rule without a prefix applies to the whole bucket. Test new rules in a test bucket first or with a narrow prefix.
  • Existing rules overwritten: put-bucket-lifecycle-configuration replaces the whole configuration. Read the current configuration first and extend it.
  • Storage does not drop right away: lifecycle rules run in the background. It can take a while until expired objects are removed.
  • Object disappears, storage stays used: with versioning on, Expiration only sets a delete marker. Add NoncurrentVersionExpiration so the data is actually deleted.
  • Locked data stays: Object Lock takes precedence over lifecycle rules.

Next