我之前已经有两个错误,每次尝试将文件上传到s3存储桶时,这都是最新的错误:
PUT https://cactustestphp.s3.us-west-1.amazonaws.com/videouploads/my-image.png` resulted in a `403
Forbidden` response: AccessDeniedAccess Denied33D5F8 (truncated...) AccessDenied (client):
Access Denied - AccessDeniedAccess
如果有人对我为什么遇到此问题有任何想法,请随时回复!我在下面发布了我的用户和存储桶策略,以防万一出现任何可见的错误。
这是我的php代码:
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'US-West',
'credentials' => [
'key' => 'garbage',
'secret' => 'garbage'
]
]);
$bucketName = 'garbage';
$file_Path = __DIR__ . '/my-image.png';
$key = basename($file_Path);
// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$result = $s3->putObject([
'Bucket' => $bucketName,
'Key' => 'videouploads/' . $key,
'Body' => fopen($file_Path, 'r'),
'ACL' => 'public-read',
]);
echo $result->get('ObjectURL');
} catch (Aws\S3\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
echo $e->getMessage();
}
?>
我的存储桶策略:
{
"Version": "2012-10-17",
"Id": "Policy1488494182833",
"Statement": [
{
"Sid": "Stmt1488493308547",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::056984788586:user/cactustest123"
},
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetBucketLocation",
"s3:Get*",
"s3:Put*"
],
"Resource": "arn:aws:s3:::cactustestphp"
}
]
}
我的用户政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:PutObject",
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::*"
]
}
]
}
答案 0 :(得分:0)
请检查您的IAM用户或角色是否对该存储桶具有足够的权限,还请查看存储桶策略,以确保没有诸如KMS SSE强制执行之类的策略。