Object lifecycles
Object lifecycles determine the retention period of objects uploaded to your bucket and allow you to specify when objects should transition from Standard storage to Infrequent Access storage.
A lifecycle configuration is a collection of lifecycle rules that define actions to apply to objects during their lifetime.
For example, you can create an object lifecycle rule to delete objects after 90 days, or you can set a rule to transition objects to Infrequent Access storage after 30 days.
- Objects will typically be removed from a bucket within 24 hours of the
x-amz-expiration
value. - When a lifecycle configuration is applied that deletes objects, newly uploaded objects'
x-amz-expiration
value immediately reflects the expiration based on the new rules, but existing objects may experience a delay. Most objects will be transitioned within 24 hours but may take longer depending on the number of objects in the bucket. While objects are being migrated, you may see old applied rules from the previous configuration. - An object is no longer billable once it has been deleted.
- Buckets have a default lifecycle rule to expire multipart uploads seven days after initiation.
- When an object is transitioned from Standard storage to Infrequent Access storage, a Class A operation is incurred.
- When rules conflict and specify both a storage class transition and expire transition within a 24 hour period, the expire (or delete) lifecycle transition takes precedence over transitioning storage class.
When you create an object lifecycle rule, you can specify which prefix you would like it to apply to.
- Note that object lifecycles currently has a 1000 rule maximum.
- Managing object lifecycles is a bucket-level action, and requires an API token with the
Workers R2 Storage Write
permission group.
- From the Cloudflare dashboard, select R2.
- Locate and select your bucket from the list.
- From the bucket page, select Settings.
- Under Object lifecycle rules, select Add rule.
- Fill out the fields for the new rule.
- When you are done, select Add rule.
- Install
npm
↗. - Install Wrangler, the Developer Platform CLI.
- Log in to Wrangler with the
wrangler login
command. - Add a lifecycle rule to your bucket by running the
r2 bucket lifecycle add
command.
Alternatively you can set the entire lifecycle configuration for a bucket from a JSON file using the r2 bucket lifecycle set
command.
The JSON file should be in the format of the request body of the put object lifecycle configuration API.
Below is an example of configuring a lifecycle configuration (a collection of lifecycle rules) with different sets of rules for different potential use cases.
To get the list of lifecycle rules associated with your bucket, run the r2 bucket lifecycle list
command.
- From the Cloudflare dashboard, select R2.
- Locate and select your bucket from the list.
- From the bucket page, select Settings.
- Under Object lifecycle rules, select the rules you would like to delete.
- When you are done, select Delete rule(s).
To remove a specific lifecycle rule from your bucket, run the r2 bucket lifecycle remove
command.