Amazon S3: Strange Mistake - “Sometimes” SignatureDoesNotMatch, Sometimes It Makes

I am developing code for salesforce. We use the Force.com for Amazon Web Services app from Appexchange. Application provided by Amazon.

I am downloading files from Amazon S3 on a machine.

Sometimes I get the error below. Interestingly, only sometimes I get this error, the rest of the time that 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. It expires 1 hour after the link is generated; therefore, this may not be a problem.

 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 the class provided by Amazon, I think it should work well all the time.

Can someone clarify why S3 can give this error only sometimes?

+7
source share
2 answers

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

Example URL for a file on Amazon S3 -

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

This is where the signature is created by the classes provided by Amazon.

For unknown reasons, Force.com's Amazon Web Services application has created a signature that contains SPACES.

eg. In this URL space, the space is replaced with "+".

To get rid of the problem, just the URL encodes the signature. The encoding will replace the spaces with a special character, and the problem will be solved.

+10
source

Are you using the Java SDK? Which version?

In version 1.4.4, an error appeared, which, it seems to me, has been fixed in recent releases. As soon as I upgraded to buggy, I had problems with intermittent signatures when using SQS, and I saw a post on the AWS forums about some people reporting the same release with DynamoDB. Now I upgraded to version 1.4.7, and the error disappeared.

Perhaps you see the same error!

0
source

All Articles