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=
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
Note: You may need to put your credit card details here.
Step 3: Create a bucket
Set a bucket name and either pick a location or leave it automatic.
Step 4: Make a note of the public details on the settings page
In this case, we make a note of:
- Name: my-bucket
- Region: weur
- S3 Endpoint: https://1995adfbb10a5f8c4b3407a8be2a66ab.r2.cloudflarestorage.com
- Note: make sure you don’t include /bucket-name at the end or you might end up with it twice.
Step 5: Access (secrets)
Go back to R2 main page and you should see your list of buckets.
Then click ‘Manage R2 API Tokens’
Create API Token
- Set the name of your token to something you can remember.
- Give it access to Object Read & Write
- 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)