R2 buckets get automated cleanup rules
Cloudflare has made Object Lifecycle Management generally available for R2, its S3-compatible object storage service. The feature lets developers define rules that automatically delete objects or abort incomplete multipart uploads after a specified period, helping to rein in storage costs for data that doesn't need to be kept indefinitely.
The launch follows R2's debut last year, which removed the egress fees that can account for more than half of a typical object storage bill. Since then, tens of thousands of developers have adopted R2 for a variety of applications, but many of those workloads generate data—logs, temporary files, and the like—that accumulates and drives up costs if never pruned.
How lifecycle rules work
Object lifecycle policies allow up to 1,000 rules per bucket. Each rule can target objects by prefix and specify an action to take after a set number of days: either delete the uploaded objects or abort incomplete multipart uploads that may be lingering and consuming storage.
For example, a rule that deletes objects after 30 days could be used to automatically clear outdated logs or temporary files without manual intervention.
Configuration options
Cloudflare dashboard
Users can set up lifecycle rules through the R2 dashboard with a few clicks:

S3-compatible API
Because R2 exposes an S3-compatible API, existing lifecycle policy configurations can be applied to R2 buckets with minimal changes. The AWS SDK for JavaScript can be used to set a bucket's lifecycle policy programmatically, requiring only an R2 Access Key for authentication:
import S3 from "aws-sdk/clients/s3.js";
const client = new S3({
endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: ACCESS_KEY_ID, // fill in your own
secretAccessKey: SECRET_ACCESS_KEY, // fill in your own
},
region: "auto",
});
await client
.putBucketLifecycleConfiguration({
LifecycleConfiguration: {
Bucket: "testBucket",
Rules: [
// Example: deleting objects by age
// Delete logs older than 90 days
{
ID: "Delete logs after 90 days",
Filter: {
Prefix: "logs/",
},
Expiration: {
Days: 90,
},
},
// Example: abort all incomplete multipart uploads after a week
{
ID: "Abort incomplete multipart uploads",
AbortIncompleteMultipartUpload: {
DaysAfterInitiation: 7,
},
},
],
},
})
.promise();
Full documentation for lifecycle policies, including dashboard and API configuration details, is available on the Cloudflare developers site.
Roadmap and feedback
While lifecycle rules address the cleanup of ephemeral data, Cloudflare is also working on lower-cost storage tiers for objects that need to be retained but are infrequently accessed—such as long tail user-generated content and archive data. Developers interested in early access can join the waitlist.
Feedback and questions about R2 can be shared via the Cloudflare Developers Discord community.



