gpt4 book ai didi

PHP Amazon SDK,S3 存储桶访问被拒绝

转载 作者:可可西里 更新时间:2023-11-01 00:12:55 24 4
gpt4 key购买 nike

我第一次尝试使用PHP AWS SDK ("aws/aws-sdk-php": "^3.19") 来使用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

关于PHP Amazon SDK,S3 存储桶访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39849949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com