Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3: Strange Error -' Sometimes' SignatureDoesNotMatch, sometimes it does

I am developing code for salesforce. We are using 'Force.com for Amazon Web Services' App from Appexchange. The app is provided by Amazon.

I am downloading files from Amazon S3 on a machine.

Sometimes I am getting the below mentioned error. Interesting thing is, only sometimes I get this error, rest of the times it works, even for the same file.

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>

I tried using both URL patterns provided by Amazon. Expires is set for 1hr after link generation, hence may not be an issue.

URL1:- http://adminportal.s3.amazonaws.com/sample.pdf?AWSAccessKeyId=AKIAIRUZSRRCVSLXZCIA&Expires=1372653478&Signature=RvMJ1gJL+qNKmnRkqzuytmlUTGQ=
URL2:- http://s3.amazonaws.com/adminportal/sample.pdf?AWSAccessKeyId=AKIAIRUZSRRCVSLXZCIA&Expires=1372658253&Signature=%2FmI0m0PTlHJpJ%2FP5d%2FX3OApqzcI%3D

The signature is generated by class provided by Amazon, I guess it must work well all of the times.

Can someone elaborate why would S3 give this error only sometimes?

like image 792
Ganesh Bhosle Avatar asked Jul 01 '13 05:07

Ganesh Bhosle


1 Answers

Finally I was able to solve this problem, here is how?

Sample URL for file on Amazon S3 is-

http://adminportal.s3.amazonaws.com/sample.pdf?AWSAccessKeyId=AKIAIRUZSRRCVSLXZCIA&Expires=1372653478&Signature=RvMJ1gJL+qNKmnRkqzuytmlUTGQ=

Here the Signature is generated by classes provided by Amazon.

For unknown reasons, 'Force.com for Amazon Web Services' app was generating signature which contain SPACES.

E.g. In the given URL, space is replaced by '+'.

To get rid of the problem, just URL encode the signature. Encoding will replace spaces with special character and problem will be resolved.

like image 158
Ganesh Bhosle Avatar answered Sep 27 '22 19:09

Ganesh Bhosle