Skip to content
Home / Migrations / AWS S3Cloudflare R2

AWS S3 Cloudflare R2

easy

R2 has zero egress fees vs S3's $0.09/GB. R2 is S3-compatible — just change the endpoint. Ideal for assets served to users.

Estimated: 1-3h · 5 steps
Progress0%
Step 1: Create R2 bucket

Cloudflare Dashboard → R2 → Create Bucket. Note the account ID.

Step 2: Create API token

R2 → Manage API Tokens → Create API Token with R2 permissions.

Step 3: Update SDK config

R2 is S3-compatible. Change endpoint, keep the same AWS SDK.

const r2 = new S3Client({
  region: 'auto',
  endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
  credentials: { accessKeyId: R2_ACCESS_KEY, secretAccessKey: R2_SECRET_KEY }
})
Step 4: Migrate existing objects

Use rclone to copy objects from S3 to R2.

rclone copy s3:my-bucket r2:my-bucket --transfers 32
Step 5: Update URLs

Enable public R2 domain or custom domain. Update any hardcoded S3 URLs.

Objects accessible, uploads working, zero egress charges