AWS S3在通过URL获取图像时访问被拒绝。

7 浏览
0 Comments

AWS S3在通过URL获取图像时访问被拒绝。

我正在使用AWS EC2 Ubuntu Machine,尝试从AWS S3获取图像,但每次都会显示以下错误信息。

InvalidArgument

使用AWS KMS托管密钥指定的请求需要AWS Signature Version 4。

Authorization

null

7C8B4BF1CE2FDC9E

/L5kjuOET4XFgGter2eFHX+aRSvVm/7VVmIBqQE/oMLeQZ1ditSMZuHPOlsMaKi8hYRnGilTqZY=

这是我的存储桶策略:

{

"Version": "2012-10-17",

"Id": "Policy1441213815928",

"Statement": [

{

"Sid": "Stmt1441213813464",

"Effect": "Allow",

"Principal": "*",

"Action": "s3:GetObject",

"Resource": "arn:aws:s3:::mytest.sample/*"

}

]

}

这是我的代码:

require 'aws-autoloader.php';

$credentials = new Aws\Credentials\Credentials('key', 'key');

$bucketName = "mytest.sample";

$s3 = new Aws\S3\S3Client([

'signature' => 'v4',

'version' => 'latest',

'region' => 'ap-southeast-1',

'credentials' => $credentials,

'http' => [

'verify' => '/home/ubuntu/cacert.pem'

],

'Statement' => [

'Action ' => "*",

],

]);

$result = $s3->getObject(array(

'Bucket' => $bucketName,

'Key' => 'about_us.jpg',

));

Html部分:

编辑(Michael - sqlbot):这里我正在使用默认的KMS。

try块:

try {

$result = $this->Amazon->S3->putObject(array(

'Bucket' => 'mytest.sample',

'ACL' => 'authenticated-read',

'Key' => $newfilename,

'ServerSideEncryption' => 'aws:kms',

'SourceFile' => $filepath,

'ContentType' => mime_content_type($filepath),

'debug' => [

'logfn' => function ($msg) {

echo $msg . "\n";

},

'stream_size' => 0,

'scrub_auth' => true,

'http' => true,

],

));

} catch (S3Exception $e) {

echo $e->getMessage() . "\n";

}

如果需要更多信息,请告诉我。

0