Skip to content
AnswerWell geo Documentation

Research · 6 min read · Answerwell

Wrangler R2 Bucket, Object, CORS, and Lifecycle Commands

How to create R2 buckets, upload objects, and manage CORS, domains, lifecycle, locks, notifications, and Sippy with Wrangler CLI.

This page summarises Cloudflare documentation for managing R2 object storage through Wrangler: bucket lifecycle, public URLs, CORS, custom domains, retention rules, event notifications, migration with Sippy, and basic object upload/download/delete. The same command reference appears in the R2 Wrangler commands reference.

Manage your R2 configurations using Wrangler.

— Cloudflare, R2

Wrangler exposes two command groups: r2 bucket for buckets and their policies, and r2 object for individual objects. Both are intended for data accessed from Workers via the R2 API.

The r2 bucket commands allow you to manage application data in the Cloudflare network to be accessed from Workers using the R2 API.

— Cloudflare, Wrangler commands — r2 bucket

Wrangler R2 CLI: when to use bucket vs object commands

Section titled “Wrangler R2 CLI: when to use bucket vs object commands”

Use wrangler r2 bucket when you need to create or delete buckets, inspect bucket metadata, configure CORS, expose buckets on r2.dev or a custom domain, set lifecycle or lock rules, wire event notifications to a queue, or enable Sippy migration from AWS or GCS. Use wrangler r2 object when you need to put, get, or delete a single object by key—typical for scripts, debugging, and local development.

The r2 object commands allow you to manage application data in the Cloudflare network to be accessed from Workers using the R2 API.

— Cloudflare, Wrangler commands — r2 object

Run commands with your package manager prefix, for example npx wrangler, yarn wrangler, or pnpm wrangler. Many bucket operations accept --jurisdiction (alias --J) to target the jurisdiction where the bucket exists; omit it only when your account default applies.

Across R2 subcommands, Wrangler supports shared flags such as --cwd, --config / --c, --env / --e, --env-file, --profile, and --v / --version. Use --env when the bucket binding or credentials differ per environment in wrangler.toml or wrangler.jsonc.

r2 bucket create and list: provision a new bucket from the terminal

Section titled “r2 bucket create and list: provision a new bucket from the terminal”

r2 bucket create creates a bucket. The only required argument is the bucket NAME.

Flag Purpose
--location Optional hint for geographic placement
--storage-class / --s Default storage class for new uploads
--jurisdiction / --J Jurisdiction for the new bucket
--update-config + --binding Add the bucket to your Worker config automatically
--use-remote Use a remote binding when adding the resource to config
npx wrangler r2 bucket create my-app-data --binding MY_BUCKET --update-config

r2 bucket list lists buckets (optional --jurisdiction). r2 bucket info returns details for one bucket; add --json for machine-readable output. r2 bucket delete removes a bucket when it is empty and you no longer need it.

r2 object put, get, and delete: upload and fetch files by key

Section titled “r2 object put, get, and delete: upload and fetch files by key”

Object commands take OBJECTPATH in the form `{bucket}/{key}` (for example my-app-data/uploads/photo.jpg).

Command Typical use
r2 object put Upload a file (--file / -f) or stdin (--pipe / -p)
r2 object get Download to --file or stdout via --pipe
r2 object delete Remove one object

r2 object put accepts HTTP metadata flags: --content-type, --content-disposition, --content-encoding, --content-language, --cache-control, --expires, and per-object --storage-class. For local Miniflare-style persistence, use --local, --remote, and --persist-to on get/put/delete.

npx wrangler r2 object put my-app-data/config.json --file ./config.json --content-type application/json --remote

Some object and lifecycle operations may prompt for Basin Catalog validation unless you pass --force / -y.

r2 bucket CORS: browser access to bucket objects

Section titled “r2 bucket CORS: browser access to bucket objects”

Browsers enforce CORS. r2 bucket cors set applies rules from a JSON file (--file, required). r2 bucket cors list shows current rules; r2 bucket cors delete clears them. Destructive CORS changes accept --force to skip confirmation.

r2.dev public URL: enable and disable dev-url for quick testing

Section titled “r2.dev public URL: enable and disable dev-url for quick testing”

r2 bucket dev-url enable turns on public access via the bucket’s r2.dev URL—useful for quick tests, not a substitute for production access control. dev-url disable turns it off; dev-url get returns the URL and status. These commands support --force on enable/disable.

r2 bucket domain: custom hostname for bucket content

Section titled “r2 bucket domain: custom hostname for bucket content”

Production setups often serve R2 through your own hostname. r2 bucket domain add connects a custom domain and requires --domain and --zone-id. Optional --min-tls sets the minimum TLS version (documentation states default 1.0 if unset). domain list, domain get, domain update, and domain remove manage existing attachments.

r2 bucket lifecycle and lock: retention and compliance rules

Section titled “r2 bucket lifecycle and lock: retention and compliance rules”

Lifecycle and lock configuration are applied from JSON files, similar to CORS.

Subcommand Action
lifecycle set / lock set Replace configuration from --file
lifecycle list / lock list Show current rules
lifecycle remove / lock remove Delete one rule by --name / --id

lifecycle set documents --force as skipping confirmation and the Basin Catalog validation prompt.

r2 bucket notification: object-create and object-delete events to a queue

Section titled “r2 bucket notification: object-create and object-delete events to a queue”

r2 bucket notification create defines rules that send messages to a named --queue. Required --event-types (alias --event-type) is object-create or object-delete. Optional --prefix and --suffix filter keys; documentation notes that regular expressions are not supported. notification list and notification delete manage rules; delete requires --queue and optionally --rule for a single rule.

r2 bucket sippy: read-through migration from AWS or GCS

Section titled “r2 bucket sippy: read-through migration from AWS or GCS”

Sippy lets an R2 bucket pull missing objects from an upstream bucket. sippy enable takes the bucket name and provider-specific credentials:

  • AWS: --provider AWS, upstream --bucket, --region, --access-key-id, --secret-access-key
  • GCS: --provider GCS, --service-account-key-file or inline --client-email / --private-key
  • R2 side: --r2-access-key-id, --r2-secret-access-key

sippy get reports status; sippy disable turns Sippy off.

Common mistakes when using Wrangler R2 commands

Section titled “Common mistakes when using Wrangler R2 commands”
  • Wrong path format: Object commands need `bucket-name/object/key`, not only the key or an S3-style URL.
  • Forgetting jurisdiction: Multi-jurisdiction accounts need --jurisdiction on bucket and object calls or commands target the wrong legal region.
  • Assuming regex in notifications: Prefix/suffix filters are literal string matches, not patterns.
  • Leaving dev-url enabled: Treat r2.dev as a development shortcut, then dev-url disable or move to a controlled custom domain.
  • Deleting buckets with data: Ensure objects are removed (or migrated) before r2 bucket delete.
  1. Authenticate Wrangler for your Cloudflare account (wrangler login if needed), then run npx wrangler r2 bucket list and confirm your bucket appears. See the R2 command reference.

  2. Run npx wrangler r2 bucket info <BUCKET> --json and verify location, storage class, and jurisdiction match what you configured at create time.

  3. Upload a test object with npx wrangler r2 object put <BUCKET>/health-check.txt --file ./health-check.txt --remote, then npx wrangler r2 object get <BUCKET>/health-check.txt --pipe and confirm the content matches.

  4. If you use public access, run npx wrangler r2 bucket dev-url get <BUCKET> or npx wrangler r2 bucket domain list <BUCKET> and confirm only the hostnames you expect are active.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match the Wrangler R2 documentation or your CLI behaviour, email yimasynthetic@gmail.com with the page URL and the exact statement you believe is wrong or unclear.