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

我使用的是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次,生成了新的,使用不同的方法来传递信息(即配置文件和在代码中包含凭据),但目前没有任何工作。


当前回答

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

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

其他回答

我刚刚体验过使用AWS SDK和React Native将图像上传到S3。这是由ContentEncoding参数引起的。

删除该参数“修复”了这个问题。

由于以下原因,我得到了相同的错误。

我输入了正确的凭据,但复制粘贴。因此,可能会产生垃圾字符插入,而复制粘贴。 我已经手动输入并运行代码,现在它的工作正常

谢谢你!

我也面临着同样的问题。导致问题的代码片段:

<iframe title="PDF Viewer" src={`${docPdfLink}&embed=true`} />

对我来说,有两个问题

在链接的末尾使用embed会导致签名不匹配,所以问题就来了。 S3中的文件具有应用程序/pdf以外的内容类型,因此我甚至在固定第一点后无法渲染pdf。

下面是我在代码中所做的:

<iframe title="PDF Viewer" src={docPdfLink} />

这里是s3 bucket: s3文件内容类型 此外,我们还需要确保无论何时向s3添加或创建pdf,它都应该有应用程序内容application/pdf

我在使用Debian扩展可用的最新awscli版本(即1.11.13版本)时,在一个非aws S3端点的Docker映像中遇到了这种情况。

升级到CLI版本1.16.84解决了该问题。

要安装最新版本的CLI,使用基于Debian拉伸映像的Dockerfile,而不是:

RUN apt-get update
RUN apt-get install -y awscli
RUN aws --version

Use:

RUN apt-get update
RUN apt-get install -y python-pip
RUN pip install awscli
RUN aws --version

这可能不是OP的100%答案,但有些人可能会发现这很有用,在我的情况下,这是IDE自动完成代码的时候之一,你不检查之后:

我的豆子

new BasicAWSCredentials(storageProperties.getAccessKey(), storageProperties.getAccessKey())))

所以基本上是两个getAccessKey()而不是getSecret(),所以它应该是:

new BasicAWSCredentials(storageProperties.getAccessKey(), storageProperties.getSecret())))