Naveen Kerati
Naveen Kerati

Reputation: 971

Failed to upload a object to S3 using signed URL

I have generated signed url using latest aws cli tool. But when i put a object using curl i got signature does not match error.

curl command i used
curl -v -H "content-type:application/vnd.ms-excel" -T users.csv "https://a054.s3.amazonaws.com/upload/users.csv?AWSAccessKeyId=AKIAJ6U4CWQNUWMWSQ7Q&Expires=1499336527&Signature=gO57XqNKJ%2FmlkHDVXsL0i6Ul2CE%3D"

The error i got
<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>AKIAJ6U4CWQNUWMWSQ7Q</AWSAccessKeyId>

Should we use same key name when we upload the object.
Any help would be greatly appreciated.

Upvotes: 0

Views: 1515

Answers (2)

Naveen Kerati
Naveen Kerati

Reputation: 971

Finally it got fixed. I generated a signed url using the following node.js snippet `

var aws = require('aws-sdk');
aws.config.update({region: 'eu-west-1'});
var s3 = new aws.S3({signatureVersion: 'v4'});
const bucketName = 'a055';
const keyName = 'app_dup.js';
const signedUrlExpireSeconds = 60 * 5;
const url = s3.getSignedUrl('putObject', {
    Bucket: bucketName,
    Key: keyName,
   "ContentType":'application/javascript',
    Expires: signedUrlExpireSeconds
});
console.log(url);

Then after i tried the postman tool for uploading an object. Thanks to @runnerpaul. Key headers to be included areContent-type && Content-length`, without those you will face errors.

Upvotes: 2

runnerpaul
runnerpaul

Reputation: 7256

Unfortunately from my experience that error doesn't tell you very much.

I had a similar issue a couple of weeks ago and resolved it by passing a 'Host' key in the header. See My AWS v4 Authorization Post.

I found that if I tred o do the operation in Postman the correct signature got generated so I was able to look at what was passed in the header and include that in my code. You may want to try this. Other than that, all I can suggest is a trial and error approach. Also, AWS has some good documentation explaining how the signature is generated. Perhaps you can look through it and work out whats missing.

Upvotes: 1

Related Questions