Our review
Manage Cloudflare R2 object storage buckets and objects using the Wrangler CLI.
Strengths
- Covers all major R2 operations: buckets, objects, CORS, custom domains.
- Provides clear command examples and configurations.
- Includes bulk upload patterns and migration notes.
Limitations
- Requires Wrangler CLI installed and authenticated.
- Limited to basic operations; advanced features like Sippy migration are only briefly mentioned.
- Does not cover integration with Workers beyond the wrangler.toml binding.
When managing Cloudflare R2 buckets and objects via CLI, especially for automated or bulk operations.
When needing fine-grained permissions or advanced S3 compatibility features beyond basic operations.
Security analysis
CautionThe skill uses Bash to run Cloudflare Wrangler commands for managing R2 storage, including bucket and object deletion. While these are legitimate operations, they carry a risk of accidental or malicious data loss if misused. No injection or exfiltration risks are apparent.
- •Uses Bash to execute wrangler CLI commands that can delete R2 buckets and objects, potentially causing data loss.
Examples
Create a new R2 bucket named 'my-bucket' using Wrangler CLI.Upload all files from the ./assets directory to my-bucket/assets, preserving filenames.Configure CORS rules for my-bucket to allow requests from https://example.com with GET and PUT methods.name: r2 description: Manage Cloudflare R2 object storage buckets and objects using Wrangler CLI. Use when working with R2 buckets, uploading/downloading files, configuring custom domains, CORS, lifecycle policies, or managing R2 storage. Trigger keywords: R2, bucket, object storage, Cloudflare storage, wrangler r2. allowed-tools: Bash, Read, Grep, Glob
Cloudflare R2 Storage Management
This skill provides commands and patterns for managing Cloudflare R2 object storage using the Wrangler CLI.
Prerequisites
- Wrangler CLI installed (
npm install -g wrangleror usenpx wrangler) - Authenticated with Cloudflare (
wrangler login)
Quick Reference
Bucket Operations
# Create a bucket
wrangler r2 bucket create <BUCKET_NAME>
# List all buckets
wrangler r2 bucket list
# Delete a bucket (must be empty)
wrangler r2 bucket delete <BUCKET_NAME>
Object Operations
# Upload an object
wrangler r2 object put <BUCKET>/<KEY> --file <LOCAL_FILE> --remote
# Download an object
wrangler r2 object get <BUCKET>/<KEY> --file <LOCAL_FILE> --remote
# Delete an object
wrangler r2 object delete <BUCKET>/<KEY> --remote
Custom Domains
# Add custom domain to bucket
wrangler r2 bucket domain add <BUCKET_NAME> --domain <DOMAIN> --zone-id <ZONE_ID>
# List custom domains
wrangler r2 bucket domain list <BUCKET_NAME>
# Remove custom domain
wrangler r2 bucket domain remove <BUCKET_NAME> --domain <DOMAIN>
CORS Configuration
# Set CORS rules
wrangler r2 bucket cors put <BUCKET_NAME> --file cors.json
# Get CORS configuration
wrangler r2 bucket cors get <BUCKET_NAME>
# Clear CORS configuration
wrangler r2 bucket cors delete <BUCKET_NAME>
Example cors.json:
{
"CORSRules": [
{
"AllowedOrigins": ["https://example.com", "https://*.example.com"],
"AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3000
}
]
}
Event Notifications
# Enable notifications to a queue
wrangler r2 bucket notification create <BUCKET_NAME> \
--event-type object-create \
--queue <QUEUE_NAME>
Bucket Lock Rules
# List lock rules
wrangler r2 bucket lock list <BUCKET_NAME>
Detailed Operations
For detailed API reference and advanced usage, see REFERENCE.md.
Common Patterns
Bulk Upload Directory
# Upload all files from a directory
for file in ./assets/*; do
wrangler r2 object put my-bucket/assets/$(basename "$file") --file "$file" --remote
done
Migrate from S3 (Sippy)
R2 supports incremental migration from S3 using Sippy. Configure via the Cloudflare dashboard or API.
Public Access via Custom Domain
- Create bucket:
wrangler r2 bucket create my-bucket - Get zone ID for your domain from Cloudflare dashboard
- Add custom domain:
wrangler r2 bucket domain add my-bucket --domain assets.example.com --zone-id <ZONE_ID> - Objects are now accessible at
https://assets.example.com/<key>
wrangler.toml Binding
To use R2 in Workers, add to wrangler.toml:
[[r2_buckets]]
binding = "MY_BUCKET"
bucket_name = "my-bucket-name"
Important Notes
- Bucket names: lowercase, numbers, hyphens only (3-63 chars, no leading/trailing hyphens)
- Use
--remoteflag to interact with remote R2 (default is local dev) - R2 is S3-compatible - AWS SDK works with R2 endpoint
- No egress fees for R2
Docker Compose Architect
DevOps
Designs optimized Docker Compose configurations.
Incident Postmortem Writer
DevOps
Writes structured and blameless incident postmortem reports.
Runbook Creator
DevOps
Creates clear operational runbooks for common DevOps procedures.