3
我第一次嘗試使用PHP AWS SDK(「aws/aws-sdk-php」:「^ 3.19」)來使用S3。PHP亞馬遜SDK,S3桶拒絕訪問
我創建了一個桶: 'myfirstbucket-jeremyc'
我創建的策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::myfirstbucket-jeremyc/*"
]
}
]
}
予應用的策略的一組,然後在創建用戶 'S3-myfirstbucket-jeremyc'這個組。
我的PHP代碼:
<?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'
));
,但我得到這個錯誤:
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
你知道我錯了?
在此先感謝!
謝謝!它通過評論ACL的行或在策略中添加「s3:PutObjectAcl」來工作。 – JeremyC