简体   繁体   中英

Fetching AWS S3 Object using Presigned URL "SignatureDoesNotMatch"

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>

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'});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM