An example Worker for copying Cloudflare Pub/Sub messages to R2 storage
BSD-3-CLAUSE License
An example Cloudflare Worker that acts as an on-publish hook for Pub/Sub and copies a subset of messages to R2 object storage.
To deploy this to your own account:
account_id
in wrangler.toml
to use your own account ID[[r2_buckets]]
configuration in wrangler.toml
to reference an R2 bucket that exists in your account (see the R2 docs for more details)BROKER_PUBLIC_KEYS
environmental variable with the public key set from your own Broker — the .../pubsub/namespaces/{namespace}/brokers/{broker}/publickeys
endpoint in the API will return your broker-specific keys (docs)wrangler publish
With the Worker deployed, you can then update your Broker configuration to use the Worker as an on-publish hook by setting the on_publish.url
field to the URL of your Worker (see the docs).
BSD-3-Clause licensed. Copyright Cloudflare, Inc, 2022.