Fetching AWS S3 Object using Presigned URL "SignatureDoesNotMatch"

2.2k views Asked by At

I created a bucket in the region of Ireland, and blocked all public access on it. Moreover, I created a script to generate a presigned URL to get the object. For some reason, I always get a SignatureDoesNotMatch error. I am unable to understand the reason behind it. below is my code:

let getPresignedUrl = async () => {
    const AWS = require('aws-sdk');
    const s3 = new AWS.S3({apiVersion: '2006-03-01', region: 'eu-west-1'});

    console.log(`Starting...`);

    const params = {Bucket: 'mybucket', Key: 'potato.jpeg', Expires: 300};
    const url = await s3.getSignedUrlPromise('getObject', params);
    console.log('The URL is', url); // expires in 60 
};

getPresignedUrl();

This is the message I am receiving

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>key</AWSAccessKeyId>
<StringToSign>GET 1603525258 /mybucket/potato.jpeg</StringToSign>
</Error>
1

There are 1 answers

0
Marcox On

Try modifying this:

const s3 = new AWS.S3({apiVersion: '2006-03-01', region: 'eu-west-1'});

To this:

const s3 = new AWS.S3({apiVersion: '2006-03-01', region: 'eu-west-1', signatureVersion: 'v4'});