Auto-Expire Old Objects with a Lifecycle Rule

r2

// what it does

`add` interactively prompts for a key prefix, an age or date condition, and an action — delete the objects, transition them to Infrequent Access, or abort stale multipart uploads. Use it to auto-clean temp files and logs and cap storage cost instead of deleting by hand.

// shell

$ wrangler r2 bucket lifecycle add my-bucket
$ wrangler r2 bucket lifecycle list my-bucket

// gotcha

Lifecycle actions run asynchronously, so objects are not removed at the exact second they hit the age threshold — expiry can lag by up to roughly a day.