到目前为止,我已经在网上搜索了两天多,可能已经浏览了大部分在线记录的场景和变通方法,但到目前为止,没有一个对我有用。

我使用的是AWS SDK for PHP V2.8.7,运行在PHP 5.3上。

我试图连接到我的亚马逊S3桶与以下代码:

// 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文件如下:

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'
                ]
            ]
        ]
    ]
];

它产生以下错误:

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

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


当前回答

这些改变对我很有效。 修改代码

来自: const s3 = new AWS.S3();

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

将方法调用从POST更改为PUT。

其他回答

在我的案例中,我使用AWS签名授权方法中的postman进行请求时使用S3(大写)作为服务名

在我的情况下,我使用s3.getSignedUrl('getObject')当我需要使用s3.getSignedUrl('putObject')(因为我使用PUT上传我的文件),这就是为什么签名不匹配。

在我的情况下(python),它失败了,因为我在文件中有这两行代码,继承自一个旧的代码

http.client.HTTPConnection。_http_vsn = 10 http.client.HTTPConnection。_sich_vsn_level = 'HTTP/1.0'

就像其他人说的那样,我也遇到了同样的问题,结果证明与密码/访问秘密有关。我为s3用户生成了一个无效的密码,但它没有通知我。当尝试连接用户时,它给出了这个错误。它似乎不喜欢密码中的某些或所有符号(至少对Minio来说)

如果您是Android开发人员,并且正在使用来自AWS示例代码的签名函数,那么您很可能想知道为什么ListS3Object有效,而GetS3Object无效。这是因为当你设置setDoOutput(true)并使用GET HTTP方法时,Android的HttpURLConnection将请求切换到POST。因此,使您的签名无效。检查我的原始帖子的问题。