xx
.md

cf_r2_create

cf_r2_create asynchronously creates an R2 bucket when it does not exist and reconciles its default storage class. Existing buckets are reused. The returned resource has a name field and can be passed directly through any deps argument.

Arguments

ArgumentRequiredDescription
nameYesGlobally unique bucket name.
locationNoCreation location hint: weur, eeur, apac, wnam, enam, or oc. Existing placement cannot be changed or verified.
jurisdictionNoBucket jurisdiction: default, eu, or fedramp. The same jurisdiction is used for lookup, creation, and updates. Cannot be combined with location.
storage_classNoReconciled default storage class: Standard or InfrequentAccess. Defaults to Standard.
depsNoDependencies activated before running Wrangler. Use these to provide Wrangler, credentials, or an account ID.

Example

This example expects package.json to list "wrangler": "4.123.0" in devDependencies.

load("@cloudflare@1", "cf_r2_create")
load("@[email protected]", "npm_install")
load("@os@1", "env_prepend", "env_set")

wrangler = npm_install() + env_prepend("PATH", "node_modules/.bin")
account = env_set("CLOUDFLARE_ACCOUNT_ID", "0123456789abcdef0123456789abcdef")
assets = cf_r2_create(
    "app-assets",
    jurisdiction="eu",
    storage_class="InfrequentAccess",
    deps=[wrangler, account],
)