Use this template to create a Cloudflare Worker that will allow you to automatically delete objects older than 30 days in a R2 Bucket.
- Install wrangler using npm
npm i -g wrangler@latest
. - Login with your Cloudflare account using
wrangler login
- Create an
.env
file following the guide in the Cloudflare Workers documentation (env file will not be commited). - Get the name of the bucket you want to use with the
wrangler r2 bucket list
command. - Edit your wrangler.toml file and change
YOUR BUCKET NAME
with the name of the bucket you want to bind. - Run
wrangler publish
and the worker will be created.
You can change the name of the Worker simply by changing the name=
variable in your wrangler.toml file
Just go to wrangler.toml and replace crons = [ "0 8 * * *" ]
with your needed crons (crons tutorial)