Skip to content

Lifecycle

Preview

Lifecycle rules clean up content a bucket no longer needs:

  • Delete files some days after they were last modified, or after a given date.
  • In buckets with versioning, permanently delete noncurrent versions after some days, and clean up files that have only a delete marker left.
  • Abort multipart uploads that started long ago and never finished, and free the uploaded parts.

Lifecycle is in preview. It is live on the storage side, and the console entry is rolling out account by account: accounts that don't have it yet won't see the Lifecycle tab on the bucket page. To use it early, please contact support.

Deletions made by rules can't be undone. Without rules, the system never deletes anything in a bucket automatically, and there are no default rules.

When rules run

Rules run once a day at 03:00 (Beijing time), and each run applies only rules saved before 03:00. There's no extra waiting period after you save:

Saved atFirst run
Before 03:00 (for example, 02:50)03:00 the same day
After 03:00 (for example, 03:10 or 14:00)03:00 the next day
  • If the rules change while a run is in progress, that day's run for the bucket stops, and the new rules apply from 03:00 the next day.
  • There can be up to about a day between a file expiring and it actually being deleted, and it's billed as usual in the meantime.

Create a rule

Go to Object storage › Buckets › click the bucket name › Lifecycle.

The Lifecycle page: the rule list, run status with estimated impact, and recent activity

Create a rule

Click Create rule and enter a Rule name. Recent activity uses it to show which rule deleted what.

Choose the scope

Choose Entire bucket or Prefix, and optionally filter further by tags and file size. See Scope.

Choose actions

Choose at least one action. See Actions. The bottom of the dialog sums up what the rule will do in one sentence.

Save the rules

You can add several rules, then click Save rules when you're done. The confirmation lists the actions that can't be undone and when the next run is.

Scope

ConditionDescription
PrefixFiles whose object key starts with it. logs/ means every file in the logs folder; a prefix without a trailing / matches names that start with it. Up to 1024 bytes
TagsOnly files that have all of these tags. Tag keys are 1 to 128 characters, and values up to 256 characters
Files larger than, Files smaller thanFilters by file size; the lower bound must be smaller than the upper bound

Actions

ActionDescription
Expire current versionsExpires files some days after they were last modified, or from a given date
Expire noncurrent versionsPermanently deletes noncurrent versions some days after they became noncurrent, optionally always keeping the newest few (1 to 100). Runs only in buckets with versioning enabled
Remove delete markersWhen all versions of a file have been cleaned up and only a delete marker is left, removes that marker too. Runs only in buckets with versioning enabled
Abort multipart uploadAborts multipart uploads that are still unfinished some days after they started, and removes the uploaded parts

What "Expire current versions" does depends on the versioning state:

Versioning stateEffect of expiration
Not enabledPermanently deletes the file; it can't be recovered
EnabledAdds a delete marker so the file disappears from the list. The data becomes a noncurrent version and is still kept and billed. To actually free the space, also set up "Expire noncurrent versions"
SuspendedRemoves the copy written while suspended and leaves a delete marker

Rule limits:

  • Up to 1000 rules per bucket. Rule names are up to 255 characters and must be unique.
  • Dates are midnight UTC, which is 08:00 Beijing time. If the date has passed, the next run after you save immediately processes every file in scope, and files written later are processed too.
  • "Remove delete markers" can't be combined with tag filters.
  • "Abort multipart upload" can't be combined with tag or file size filters, and uploads still receiving parts recently aren't aborted.
  • Expiring noncurrent versions deletes them permanently. Versions protected by Object Lock are skipped.

Estimated impact and activity

A few minutes after you save, the page shows the Estimated impact of this version of the rules: based on the current data, how many items the rules will process and how much space that is. It's only a dry run and deletes nothing, and the rules don't wait for it. For rules saved shortly before 03:00, it may appear only after the run. The actual numbers depend on the data at run time.

Run status shows whether today's run has finished and how many items were deleted, skipped, or failed. Recent activity lists what the rules actually deleted, covering only the latest 50 entries from the last 30 days. Each entry's result is one of:

ResultMeaning
DeletedDeleted
Skipped: protected by Object LockThe version is within its retention period or under legal hold. It wasn't deleted this time and will be checked again in the next run
FailedThis item wasn't processed and will be retried in the next run
ScenarioRule
Logs and temporary filesPrefix logs/, expire current versions 30 days after last modification
Buckets with versioningEntire bucket, expire noncurrent versions 30 days after they become noncurrent, keeping the newest 3, plus remove delete markers
Every bucketEntire bucket, abort multipart uploads 7 days after they start

Use the S3 API

OperationDescription
GetBucketLifecycleConfigurationRequires read permission. With no rules, returns 404 NoSuchLifecycleConfiguration
PutBucketLifecycleConfigurationReplaces all rules; requires admin permission on the bucket
DeleteBucketLifecycleDeletes all rules; requires admin permission on the bucket

Sub-user AccessKeys can upload files (which creates versions automatically), delete files without a version ID (which adds a delete marker and requires write permission), list versions, read specific versions, and read the versioning, lifecycle, and Object Lock settings.

The following require admin permission on the bucket, which sub-user AccessKeys don't have, so do them in the console: enabling and suspending versioning, setting and deleting lifecycle rules, enabling Object Lock and setting the default retention, legal hold, setting compliance retention, permanently deleting by version ID (including items with a version ID in a batch delete), and bypassing governance mode.

Supported rule elements: Filter (Prefix, Tag, ObjectSizeGreaterThan, ObjectSizeLessThan, combined with And), Expiration (Days, Date, ExpiredObjectDeleteMarker), NoncurrentVersionExpiration (NoncurrentDays, NewerNoncurrentVersions), and AbortIncompleteMultipartUpload (DaysAfterInitiation).

Differences from AWS

ItemS4 behavior
Storage class transitionsNot supported. Configurations with Transition or NoncurrentVersionTransition return 400
Run timeOne run a day at 03:00 (Beijing time), applying only rules saved before 03:00. There can be up to about a day between expiration and deletion, billed as usual in the meantime
Folder objectsKeys ending in / are never deleted by rules. Once the files in a folder are deleted, the empty folder is cleaned up automatically (folder objects you created yourself are kept)
Past datesTake effect immediately and keep applying to files written later (same as AWS)
Aborting multipart uploadsSkips uploads still receiving parts recently; can't be combined with file size filters
Expiration rules with only DaysWhen cleaning up files that have only a delete marker left, the delete marker itself must be Days days old
Rule IDNot generated when omitted; returned as-is when read
Filter syntaxA prefix combined with tag or size conditions must go inside And, or the request returns 400 MalformedXML (same as AWS)
x-amz-expirationNot included in file read and write responses
Changed during a runIf a file is rewritten after it was scanned, that item is skipped and handled at most one run later