DEV Community

Jack Bridger
Jack Bridger

Posted on • Edited on • Originally published at streampot.io

How to setup Cloudflare R2 bucket & generate access key

Since R2 is S3 compatible, I am using Cloudflare R2 with the AWS Node S3 SDK. But I realised Cloudflare’s website is not very intuitive when it comes to getting the details you need. So I made a walkthrough.

Typically you need the below details to initialise access.



S3_ACCESS_KEY=
S3_SECRET_KEY=
S3_BUCKET_NAME=
S3_ENDPOINT=
S3_REGION=


Enter fullscreen mode Exit fullscreen mode

In this tutorial, I’ll show you how to get them

Step 1: Create a Cloudflare account

Go to https://dash.cloudflare.com/sign-up

Step 2: Go to R2 on the left hand panel

Image description

Note: You may need to put your credit card details here.

Step 3: Create a bucket

Image description

Set a bucket name and either pick a location or leave it automatic.

Image description

Step 4: Make a note of the public details on the settings page

Image description

Image description

In this case, we make a note of:

Step 5: Access (secrets)

Go back to R2 main page and you should see your list of buckets.

Then click ‘Manage R2 API Tokens’

Image description

Create API Token

Image description

Image description

  1. Set the name of your token to something you can remember.
  2. Give it access to Object Read & Write
  3. Apply to only the bucket you just created

Then press ‘Create API Token’

On the next page, you will be given your

  • Access Key ID
  • Secret Access Key

So now we have everything we need to make API calls to R2.

Troubleshooting

  • For some reason, Cloudflare display region in upper case in some places. But you must use lower case or it won't work. I.e. use 'weur'. Do not use 'WEUR'.

Top comments (0)