Amazon S3 - 如何修复“我们计算的请求签名与签名不匹配"错误? [英] Amazon S3 - How to fix 'The request signature we calculated does not match the signature' error?

查看:96
本文介绍了Amazon S3 - 如何修复“我们计算的请求签名与签名不匹配"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网上搜索了两天多,并且可能浏览了大部分在线记录的场景和解决方法,但到目前为止没有任何效果.

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.

我正在使用 AWS SDK,用于在 PHP 5.3 上运行的 PHP V2.8.7.

I am on AWS SDK for PHP V2.8.7 running on PHP 5.3.

我正在尝试使用以下代码连接到我的 Amazon S3 存储桶:

I am trying to connect to my Amazon 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();
}

我的config.php文件如下:

My config.php file is as follows:

return [
    // Bootstrap the configuration file with AWS specific features
    'includes' => ['_aws'],
    'services' => [
        // 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' => [
            'params' => [
                'credentials' => [
                    'key'    => 'key',
                    'secret' => 'secret'
                ]
            ]
        ]
    ]
];

它产生以下错误:

我们计算的请求签名与您提供的签名不匹配.检查您的密钥和签名方法.

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

我已经检查了至少 20 次我的访问密钥和秘密,生成了新的,使用了不同的方法来传递信息(即配置文件和代码中的凭据),但目前没有任何工作.

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.

推荐答案

我在 nodejs 中遇到了同样的错误.但是在 s3 构造函数中添加 signatureVersion 对我有帮助:

I had the same error in nodejs. But adding signatureVersion in s3 constructor helped me:

const s3 = new AWS.S3({
  apiVersion: '2006-03-01',
  signatureVersion: 'v4',
});

这篇关于Amazon S3 - 如何修复“我们计算的请求签名与签名不匹配"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆