401 Unauthorized for R2 Access Tokens

For Workes & Pages, what is the name of the domain?

Issue is not related to “Workers & Pages”. It is with R2.

What is the error number?

401

What is the error message?

upload failed: ./test.txt to s3://testbucket/test.txt An error occurred (Unauthorized) when calling the PutObject operation: Unauthorized

What is the issue or error you’re encountering

I’m unable to access any of my R2 buckets using the s3 API.

What steps have you taken to resolve the issue?

I removed all the existing R2 API tokens.
I created a brand new bucket.
I then created a brand new API Token with the below:
> Object Read & Write: Allows the ability to read, write, and list objects in specific buckets.
> Apply to specific buckets only => Chose my brand new bucket
> TTL - Forever
> Client IP Address Filtering - Didn’t even touch this field. Both Include and Exclude text-input fields are left blank.
I clicked on “Create API token”. The next page showed me “Access key ID” and “Secret Access Key”

In my ubuntu, opened up a new terminal and executed “aws configure”.
Copy and pasted “Access Key ID”
Copy and pasted “Secret Access Key”
For region, typed “auto”
For output, typed “json”.
Pressed enter.

Then, tried uploading a file like,
aws s3 cp test.txt s3://testbucket/test.txt --endpoint-url https://.r2.cloudflarestorage.com

But it fails with 401 error.

What are the steps to reproduce the issue?

Pretty much the steps I mentioned prior is enough.

An error occurred (InternalError) when calling the PutObject operation (reached max retries: 2): We encountered an internal error. Please try again

I’m getting this error now.

1 Like