How to fix 'The request signature we calculated does not match the signature' error?

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

I have searched on the web for over two days now, and probably have looked through most of the online documented scenarios and workarounds, but nothing worked for me so far.

I am on AWS SDK for PHP V2.8.7 running on PHP 5.3. I am trying to connect to my S3 bucket with the following code:

// Create a `Aws` object using a configuration file          $aws = Aws::factory('config.php');          // Get the client from the service locator by namespace         $s3Client = $aws->get('s3');          $bucket = "xxx";         $keyname = "xxx";          try {             $result = $s3Client->putObject(array(                 'Bucket'        =>      $bucket,                 'Key'           =>      $keyname,                 'Body'          =>      'Hello World!'             ));             $file_error = false;         } catch (Exception $e) {             $file_error = true;             echo $e->getMessage();             die();         }         //   

My config.php file is as follows:

<?php  return array(     // Bootstrap the configuration file with AWS specific features     'includes' => array('_aws'),     'services' => array(         // All AWS clients extend from 'default_settings'. Here we are         // overriding 'default_settings' with our default credentials and         // providing a default region setting.         'default_settings' => array(             'params' => array(                 'credentials' => array(                     'key'    => 'key',                     'secret' => 'secret'                 )             )         )     ) ); 

It is producing the following error:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

I've already checked my access key and secret at least 20 times, generated new ones, used different methods to pass in the information (i.e. profile and including credentials in code) but nothing is working at the moment.

回答1:

After two days of debugging, I finally discovered the problem...

The key I was assigning to the object started with a period i.e. ..\images\ABC.jpg, and this caused the error to occur.

I wish the API provides more meaningful and relevant error message, alas, I hope this will help someone else out there!



回答2:

I get this error with the wrong credentials. I think there were invisible characters when I pasted it originally.



回答3:

I had the same problem when tried to copy an object with some UTF8 characters. Below is a JS example:

Solved by encoding the CopySource with encodeURIComponent()



回答4:

I just experienced this uploading an image to S3 using the AWS SDK with React Native. It turned out to be caused by the ContentEncoding parameter.

Removing that parameter "fixed" the issue.



回答5:

Actually in Java i was getting same error.After spending 4 hours to debug it what i found that that the problem was in meta data in S3 Objects as there was space while sitting cache controls in s3 files.This space was allowed in 1.6.* version but in 1.11.* it is disallowed and thus was throwing the signature mismatch error



回答6:

I had a similar error, but for me it seemed to be caused by re-using an IAM user to work with S3 in two different Elastic Beanstalk environments. I treated the symptom by creating an identically permissioned IAM user for each environment and that made the error go away.



回答7:

If none of the other mentioned solution works for you , then try using

aws configure 

this command will open a set of options asking for keys, region and output format.

Hope this helps!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!