S3 Api SignatureDoesNotMatch

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

cloudflarestorage.com

What is the error number?

SignatureDoesNotMatch

What is the error message?

SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your secret access key and signing method.

What is the issue or error you’re encountering

Trying to upload files to an R2 bucket from my local machine and getting a signature does not match error

What steps have you taken to resolve the issue?

General debugging.

What are the steps to reproduce the issue?

Writing a script that needs to upload some files to an R2 bucket at build time (so really this is just running as normal nodejs). Trying to use the S3 API.

Code is really simple, basically straight from the examples:

import {
S3Client,
ListBucketsCommand,
ListObjectsV2Command,
GetObjectCommand,
PutObjectCommand,
} from “@aws-sdk/client-s3”;
import { createHash } from “node:crypto”;

const hashedSecretKey = createHash(‘sha256’).update(R2_S3_SECRET).digest(‘hex’);

const S3 = new S3Client({
region: “auto”,
endpoint: R2_S3_ENDPOINT,
credentials: {
accessKeyId: R2_S3_CLIENT,
secretAccessKey: hashedSecretKey,
},
});

console.log(await S3.send(new ListObjectsV2Command ({
Bucket: R2_BUCKET_NAME,
})));

Getting the error:

SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your secret access key and signing method.

Running this from my local machine.

I’ve tried using a custom public domain. CORS is set up, but this is not a CORS issue. Public Access is enabled FWIW.

SOLVED:
Solution is to not hash the secret. Docs should be updated.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.