PHP Amazon SDK, S3 Bucket Access Denied

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I try for the first time to use the PHP AWS SDK ("aws/aws-sdk-php": "^3.19") to use S3.

I created a bucket : 'myfirstbucket-jeremyc'

I created a policy :

{     "Version": "2012-10-17",     "Statement": [         {             "Effect": "Allow",             "Action": [                 "s3:PutObject",                 "s3:GetObject",                 "s3:DeleteObject"             ],             "Resource": [                 "arn:aws:s3:::myfirstbucket-jeremyc/*"             ]         }     ] } 

I applied the policy to a group and then created a user 's3-myfirstbucket-jeremyc' in this group.

My PHP code is :

<?php use Aws\S3\S3Client; use Aws\S3\Exception\S3Exception;  error_reporting(E_ALL);  require(__DIR__ . '/vendor/autoload.php');  $s3Client = S3Client::factory([     'credentials' => [         'key'    => $_SERVER['AWS_S3_CLIENT_KEY'],         'secret' => $_SERVER['AWS_S3_CLIENT_SECRET']     ],     'region' => 'eu-west-1',     'version' => 'latest',     'scheme' => 'http' ]);  $result = $s3Client->putObject(array(     'Bucket' => 'myfirstbucket-jeremyc',     'Key' => 'text.txt',     'Body' => 'Hello, world!',     'ACL' => 'public-read'     )); 

But i get this error :

Error executing "PutObject" on "http://s3-eu-west-1.amazonaws.com/myfirstbucket-jeremyc/text.txt"; AWS HTTP error: Client error: PUT http://s3-eu-west-1.amazonaws.com/myfirstbucket-jeremyc/text.txt resulted in a 403 Forbidden response

Do you know where i'm wrong ?

Thanks in advance !

回答1:

You're setting the ACL for the new object but you haven't allowed s3:PutObjectAcl.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!