Skip to content

Lifecycle rules

Lifecycle rules delete things for you on a schedule: temporary files after a few days, old versions after a month, unfinished multipart uploads after a week. Setting rules needs an Admin key.

Rule What it does Buckets
Expiration with Days or Date Deletes current objects after a number of days or on a date. On a versioned bucket it adds a delete marker instead. All
AbortIncompleteMultipartUpload Cancels multipart uploads that weren’t finished after DaysAfterInitiation days, freeing their parts. All
NoncurrentVersionExpiration Permanently deletes noncurrent versions NoncurrentDays after they were replaced, optionally keeping the newest NewerNoncurrentVersions. Versioned
Expiration with ExpiredObjectDeleteMarker Removes delete markers that no longer have any versions behind them. Versioned

Filters: by key prefix and by object size (ObjectSizeGreaterThan, ObjectSizeLessThan) on every bucket; by tags as well on buckets with versioning.

Days are counted like S3: rounded up to the next midnight UTC. Rules run in the background, so an object can stay a little while after its expiry time. Versions under object lock are never deleted by a rule.

Transitions (moving objects to another storage class) aren’t supported: Hive Buckets has one storage class, so a rule with a Transition is refused.

lifecycle.json
{
"Rules": [
{
"ID": "expire-tmp",
"Status": "Enabled",
"Filter": { "Prefix": "tmp/" },
"Expiration": { "Days": 7 }
},
{
"ID": "abort-unfinished-uploads",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 3 }
},
{
"ID": "old-versions",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"NoncurrentVersionExpiration": { "NoncurrentDays": 30, "NewerNoncurrentVersions": 3 }
}
]
}

The old-versions rule only applies to a bucket with versioning; leave it out otherwise.

Terminal window
EP=https://s3.dockhive.io
aws s3api put-bucket-lifecycle-configuration --bucket my-app-uploads \
--lifecycle-configuration file://lifecycle.json --endpoint-url $EP
aws s3api get-bucket-lifecycle-configuration --bucket my-app-uploads --endpoint-url $EP
aws s3api delete-bucket-lifecycle --bucket my-app-uploads --endpoint-url $EP