CLI (3)
Last updated Apr 21, 2026 Manage R2 buckets and objects directly from your terminal. Use CLI tools to automate tasks and manage objects.
| Tool | Best for |
|---|---|
| Wrangler | Single object operations and managing bucket settings with minimal setup |
| rclone | Bulk object operations, migrations, and syncing directories |
| AWS CLI | Existing AWS workflows or familiarity with AWS CLI |
1. Create a bucket
A bucket stores your objects in R2. To create a new R2 bucket:
- Log in to your Cloudflare account:
sh
npx wrangler login
- Create a bucket named
my-bucket:
sh
npx wrangler r2 bucket create my-bucket
If prompted, select the account you want to create the bucket in. 3. Verify the bucket was created:
sh
npx wrangler r2 bucket list
- In the Cloudflare Dashboard, go to R2 object storage. Go to Overview ↗
- Select Create bucket.
- Enter a name for your bucket.
- Select a location for your bucket and a default storage class.
- Select Create bucket.
2. Generate API credentials
CLI tools that use the S3 API (AWS CLI, rclone) require an Access Key ID and Secret Access Key. If you are using Wrangler, you can skip this step.
- In the Cloudflare dashboard, go to R2.
- Select Manage R2 API tokens.
- Select Create API token.
- Choose Object Read & Write permission and select the buckets you want to access.
- Select Create API Token.
- Copy the Access Key ID and Secret Access Key. Store these securely — you cannot view the secret again.
3. Set up a CLI tool
Wrangler is the Cloudflare Workers CLI. It authenticates with your Cloudflare account directly, so no API credentials needed.
- Install Wrangler:npmyarnpnpmbun
npm i -D wrangler
yarn add -D wrangler
pnpm add -D wrangler
bun add -d wrangler
- Log in to your Cloudflare account:
sh
wrangler login
rclone is ideal for bulk uploads, migrations, and syncing directories.
- Install rclone ↗︎ (version 1.59 or later).
- Configure a new remote:
sh
rclone config
- Create new remote by selecting
n. - Name your remote
r2 - Select Amazon S3 Compliant Storage Providers as the storage type.
- Select Cloudflare R2 as the provider.
- Select whether you would like to enter AWS credentials manually, or get it from the runtime environment.
- Enter your Access Key ID and Secret Access Key when prompted.
- Select the region to connect to (optional).
- Provide your S3 API endpoint.
The AWS CLI works with R2 by specifying a custom endpoint.
- Install the AWS CLI ↗︎ for your operating system.
- Configure your credentials:
sh
aws configure
- When prompted, enter:
- AWS Access Key ID: Your R2 Access Key ID
- AWS Secret Access Key: Your R2 Secret Access Key
- Default region name:
auto - Default output format:
json(or press Enter to skip)
4. Upload and download objects
(Optional) Create a test file to upload. Run this command in the directory where you plan to run the CLI commands:
echo 'Hello, R2!' > myfile.txt
# Upload myfile.txt to my-bucket
wrangler r2 object put my-bucket/myfile.txt --file ./myfile.txt
# Download myfile.txt and save it as downloaded.txt
wrangler r2 object get my-bucket/myfile.txt --file ./downloaded.txt
Refer to the Wrangler R2 commands for all available operations.
# Upload myfile.txt to my-bucket
rclone copy myfile.txt r2:my-bucket/
# Download myfile.txt from my-bucket to the current directory
rclone copy r2:my-bucket/myfile.txt .
Refer to the rclone documentation for more configuration options.
# Upload myfile.txt to my-bucket
aws s3 cp myfile.txt s3://my-bucket/ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# Download myfile.txt from my-bucket to current directory
aws s3 cp s3://my-bucket/myfile.txt ./ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# List all objects in my-bucket
aws s3 ls s3://my-bucket/ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
Refer to the AWS CLI documentation for more examples.
Next steps
Presigned URLs
Generate temporary URLs for private object access.
Public buckets
Serve files directly over HTTP with a public bucket.
CORS
Configure CORS for browser-based uploads.
Object lifecycles
Set up lifecycle rules to automatically delete old objects.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/r2/get-started/cli/#page","headline":"CLI","description":"Use R2 from the command line with Wrangler, rclone, or AWS CLI.","url":"https://developers.cloudflare.com/r2/get-started/cli/","inLanguage":"en","image":"https://developers.cloudflare.com/r2/get-started/cli/og.png?v=c663f462045ff419","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Use R2 with S3-compatible SDKs like boto3 and the AWS SDK. title: S3 image: https://developers.cloudflare.com/r2/get-started/s3/og.png?v=aa6951d9f9e9b0e8
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/r2/llms.txt
Use this file to discover all available pages before exploring further.
Docs