Configure R2 bucket event notifications to publish object-create/object-delete events to a Cloudflare Queue and consume them in a Worker.

domain: developers.cloudflare.com · 9 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Prerequisites: have an existing R2 bucket and an existing Queue (`npx wrangler queues create <MY-QUEUE-NAME>` if needed), plus either a consumer Worker or HTTP pull enabled on the queue. See https://developers.cloudflare.com/r2/buckets/event-notifications/
  2. Log in with `npx wrangler login`, then create an event notification rule: `npx wrangler r2 bucket notification create <BUCKET_NAME> --event-type <EVENT_TYPE> --queue <QUEUE_NAME>` where EVENT_TYPE is `object-create` or `object-delete`.
  3. Optionally filter which objects trigger notifications by adding `--prefix "<PREFIX_VALUE>"` and/or `--suffix "<SUFFIX_VALUE>"` to the same command; both can be combined and are ANDed together.
  4. Avoid overlapping rules for the same event type: e.g. do not add both an object-create rule with no prefix and another object-create rule scoped to `images/`, since Cloudflare disallows rule sets that could double-fire for the same event.
  5. Alternatively configure via dashboard: R2 object storage > select bucket > Settings tab > Event notifications card > Add notification > choose queue and event type(s) > Add notification.
  6. Build the consumer Worker: bind the queue as a consumer in wrangler.jsonc — {"queues": {"consumers": [{"queue": "<MY-QUEUE-NAME>", "max_batch_size": 10, "max_batch_timeout": 5}]}} — and export a `queue(batch, env, ctx)` handler that iterates `batch.messages` and reads `message.body`.
  7. Parse each message body as JSON matching the event schema: { account, action, bucket, object: { key, size, eTag }, eventTime, copySource? }. Note object.size/eTag are absent for object-delete events, and copySource is only present for CopyObject actions.
  8. Deploy the consumer Worker with `npx wrangler deploy`, then trigger a PUT/DELETE against the R2 bucket and use `npx wrangler tail` on the consumer Worker to confirm notifications arrive.
  9. You can have up to 100 event notification rules per R2 bucket; if your write volume exceeds the queue's throughput, split notification rules across multiple queues.

Known gotchas

Related routes

Produce and consume messages with Cloudflare Queues including retry configuration
cloudflare-queues · 6 steps · unrated
Send app events to AppsFlyer via the Server-to-Server (S2S) Events API v3
dev.appsflyer.com · 6 steps · unrated
Read, write, delete, and list objects in a Cloudflare R2 bucket from a Worker using the native bucket binding, including HTTP and custom metadata.
developers.cloudflare.com · 9 steps · unrated

Give your agent this knowledge — and 16,900+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans