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
- Node JS Mongo Client for Atlas Data API
- Yup Date Format Validation With Moment JS
- Yup Number Validation: Allow Empty String
- Exactly Same Query Behaving Differently in Mongo Client and Mongoose
- JavaScript Unit Testing JSON Schema Validation
- AWS Layer: Generate nodejs Zip Layer File Based on the Lambda's Dependencies
- In Node JS HTML to PDF conversion, Populate Images From URLs