Cloudflare DevelopersCD
Cloudflare Developersโ€ข3d agoโ€ข
2 replies
Faker

Access Denied using aws-sdk to interact with R2 bucket

Hello, consider the following code:

import {
  S3Client,
  ListBucketsCommand,
  ListObjectsV2Command,
  GetObjectCommand,
  PutObjectCommand,
} from "@aws-sdk/client-s3";

const S3 = new S3Client({
  region: "auto", // Required by SDK but not used by R2
  // Provide your Cloudflare account ID
  endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
  // Retrieve your S3 API credentials for your R2 bucket via API tokens (see: https://developers.cloudflare.com/r2/api/tokens)
  credentials: {
    accessKeyId: ACCESS_KEY_ID,
    secretAccessKey: SECRET_ACCESS_KEY,
  },
});

I set up everything as above, the code snippets is from the docs. But I'm getting an access denied. Does cloudflare has a bucket policy just like aws has or something like that?
B9D5A564-B39D-4393-8048-949BF5E2CC62.png
Was this page helpful?