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

Same code working locally, but not on a remote server. Migrating aws-sdk to @aws-sdk/client-s3

Using AWS S3 functionality in our node application, this issue suddenly broke our functionality for no plausible reason. The strange aspect was that the same thing worked correctly on the local server, but any remote server would throw this error.

The Solution

After trying several things with no success, the only thing that worked was upgrading the aws-sdk to version 3, which, for S3, comes as @aws-sdk/client-s3.

Here is an example of old code:

import aws from "aws-sdk";

export const s3 = new aws.S3({
  signatureVersion: "v4",
  region: "eu-north-1",
  accessKeyId: "ACBDEF",
  secretAccessKey: "GHIJKL"
});

const params = {
  Bucket: "MyBucket",
  CopySource: `/MyBucket/oldFile`,
  Key: "newFile",
};

s3.copyObject(params, error => {
  if(error){
    console.log(error);
  }
});

This above code gave the SignatureDoesNotMatch error.

Below is the same code with the newer version that resolved the error:

import { S3Client, CopyObjectCommand } from "@aws-sdk/client-s3";

const s3Client = new S3Client({
  region: "eu-north-1",
  credentials: {
    accessKeyId: "ACBDEF",
    secretAccessKey: "GHIJKL"
  },
});

const params = {
  Bucket: "MyBucket",
  CopySource: `/MyBucket/oldFile`,
  Key: "newFile",
};

 s3Client
  .send(new CopyObjectCommand(params))
  .then(() => console.log("success"))
  .catch(error => {
    console.log(error);
  });



See also

When you purchase through links on techighness.com, I may earn an affiliate commission.