Report this

What is the reason for this report?

Getting SignatureDoesNotMatch when using Custom Csn (Spaces)

Posted on April 22, 2024

We have been using DO Spaces for a few month for our production app. I’m using the following npm library to generated presigned urls: @aws-sdk/s3-request-presigner

After some complaints, today I spent time on migrating to a custom CDN. The problem is that when I setup my CDN with my own domain, I get the following error:

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><Resource>tangible-platform-files-staging/deals-fund/3786/sample.pdf</Resource><RequestId>not available</RequestId></Error>

The only change between a working link and the message above is changing my env variables to: DO_SPACES_ENDPOINT (my new domain: http://<example>.app) DO_SPACES_BUCKET (my new subdomain)

How do I correctly set up the presigned when using a Custom CDN?

const client = new S3Client({
    region: process.env.DO_SPACES_REGION,
    endpoint: process.env.DO_SPACES_ENDPOINT,
    credentials: {
      accessKeyId: process.env.DO_SPACES_KEY || 'error',
      secretAccessKey: process.env.DO_SPACES_SECRET || 'error',
    },
  });

  const fileKey = <value>;
  const bucketParams = {
    Bucket: process.env.DO_SPACES_BUCKET,
    Key: fileKey,
  };

  const command = new GetObjectCommand(bucketParams);
  const presSignedUrl = await getSignedUrl(client, command, { expiresIn: 3600 });
  return presSignedUrl;

Thank you

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.