本文介绍了PHP Amazon SDK,S3存储桶访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我第一次尝试使用PHP AWS开发工具包("aws/aws-sdk-php":"^ 3.19")来使用S3.
I try for the first time to use the PHP AWS SDK ("aws/aws-sdk-php": "^3.19") to use S3.
我创建了一个存储桶:"myfirstbucket-jeremyc"
I created a bucket : '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".
I applied the policy to a group and then created a user 's3-myfirstbucket-jeremyc' in this group.
我的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'
));
但是我遇到了这个错误:
你知道我错了吗?
提前谢谢!
推荐答案
您正在为新对象设置ACL,但您不允许s3:PutObjectAcl
.
You're setting the ACL for the new object but you haven't allowed s3:PutObjectAcl
.
这篇关于PHP Amazon SDK,S3存储桶访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!