R2 bucket management over the Cloudflare API: list, create, get, and
delete buckets. Object reads and writes use R2's S3-compatible API —
use the aws-s3 package against
https://{account_id}.r2.cloudflarestorage.com (region auto) with an
R2 access key pair.
Context Vars
cloudflare.tokencloudflare.account.id
Functions
create-bucket
fn (name: Str): Map
fn (name: Str, options: Map): Map
fn (name: Str, options: Map, opts: Map): Map
POST /accounts/{account_id}/r2/buckets - Create a bucket. options:
location_hint (apac, eeur, enam, weur, wnam, oc),
storage_class (Standard, InfrequentAccess), jurisdiction.
Example
::cloudflare::r2/create-bucket("exports", {location_hint: "enam"})
create-bucket-body
fn (name: Str, options: Map): Map
The create body: {name, locationHint?, storageClass?} from options
(location_hint/locationHint, storage_class/storageClass).
Exposed for testing.
Example
::cloudflare::r2/create-bucket-body("exports", {location_hint: "enam"}) // {name: "exports", locationHint: "enam"}
delete-bucket
fn (name: Str): Any
fn (name: Str, jurisdiction: Str?): Any
fn (name: Str, opts: Map): Any
fn (name: Str, jurisdiction: Str?, opts: Map): Any
DELETE /accounts/{account_id}/r2/buckets/{name} - Delete an empty bucket (R2 refuses a bucket that still holds objects).
Example
::cloudflare::r2/delete-bucket("exports")
get-bucket
fn (name: Str): Map
fn (name: Str, jurisdiction: Str?): Map
fn (name: Str, opts: Map): Map
fn (name: Str, jurisdiction: Str?, opts: Map): Map
GET /accounts/{account_id}/r2/buckets/{name} - One bucket: {name, creation_date, location, storage_class, jurisdiction}.
Example
bucket ::cloudflare::r2/get-bucket("exports")
bucket.location
::cloudflare::r2/get-bucket("eu-exports", "eu")
jurisdiction-headers
fn (jurisdiction: Str?): Map
The cf-r2-jurisdiction header for a jurisdiction ("eu", "fedramp",
…), or no header for null/"default". Exposed for testing.
Example
::cloudflare::r2/jurisdiction-headers("eu") // {cf-r2-jurisdiction: "eu"}
::cloudflare::r2/jurisdiction-headers("default") // {}
list-all-buckets
fn (): Vec
fn (params: Map): Vec
fn (params: Map, max: Int): Vec
fn (params: Map, opts: Map): Vec
fn (params: Map, max: Int, opts: Map): Vec
Every bucket matching params, following cursors up to max buckets
(default 10000).
Example
map(::cloudflare::r2/list-all-buckets({name_contains: "export"}, 500), %.name)
list-buckets
fn (): ::cloudflare::api/ListPage
fn (params: Map): ::cloudflare::api/ListPage
fn (params: Map, opts: Map): ::cloudflare::api/ListPage
GET /accounts/{account_id}/r2/buckets - One page of buckets.
params: name_contains, start_after, per_page (1–1000),
cursor, order (name), direction, and jurisdiction (sent as
the cf-r2-jurisdiction header). Returns a ListPage whose result
is the bucket list.
Example
page ::cloudflare::r2/list-buckets({name_contains: "export", per_page: 100})
map(page.result, %.name)
// EU buckets
::cloudflare::r2/list-buckets({jurisdiction: "eu"})
s3-endpoint
fn (account-id: Str): Str
fn (account-id: Str, jurisdiction: Str?): Str
The S3-compatible endpoint for object I/O with aws-s3:
https://{account_id}.r2.cloudflarestorage.com (.eu. / .fedramp.
inserted for those jurisdictions).
Example
::cloudflare::r2/s3-endpoint("acc123") // "https://acc123.r2.cloudflarestorage.com"
::cloudflare::r2/s3-endpoint("acc123", "eu") // "https://acc123.eu.r2.cloudflarestorage.com"