【发布时间】:2017-11-16 01:03:01
【问题描述】:
我们目前无法使用 AWS PHP SDK v. 3.36 从 S3 下载对象。通过 GetObject 方法。
我们看到以下错误:
Error executing "GetObject" on "<object path>";
AWS HTTP error: Client error: `GET <object path>` resulted in a `403 Forbidden` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calcul (truncated...) SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you
provided. Check your key and signing method.
- <?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided.
Check your key and signing method.
<remaining message redacted>
S3 客户端设置:
public function __construct($key, $secret, $region='us-east-1') {
$this->key = $key;
$this->secret = $secret;
$this->handler = new S3Client([
'credentials' => [
'key' => $key,
'secret' => $secret
],
'region' =>$region,
'version' => '2006-03-01'
]);
}
调用GetObject方法:
public function getFile($bucket, $sourcefile, $saveToDestination = null) {
$getarray = array(
'Bucket' => $bucket,
'Key' => $sourcefile,
);
if ($saveToDestination) {
$getarray['SaveAs'] = $saveToDestination;
}
return $this->handler->getObject($getarray);
}
对于有问题的 IAM 用户,提供了对 S3 的完全访问权限,并且上面使用的凭证已经过验证。
IAM 政策 (AmazonS3FullAccess):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
【问题讨论】:
标签: php amazon-web-services amazon-s3 aws-php-sdk