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
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/
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`.
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.
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.
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`.
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.
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.
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
Queues per-queue message throughput is currently 5,000 messages/second — split notification rules across multiple queues if your workload produces more events than that.
Overlapping/conflicting rules for the same event type (e.g. an unscoped object-create rule plus a prefix-scoped object-create rule) are rejected/invalid because they could double-fire a single upload.
object-create fires for PutObject, CopyObject, and CompleteMultipartUpload; object-delete fires for DeleteObject and LifecycleDeletion — plan filters around the actual trigger actions, not just the two coarse event types.
object.size and object.eTag are not present in the message payload for object-delete events, so consumer code must handle their absence.
Each queue can only have one push-based (Worker) consumer attached; you can instead enable HTTP pull consumers on the same queue as an alternative to a Worker consumer.
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?