无法将对象放入Amazon S3存储桶

时间:2020-05-12 20:11:19

标签: amazon-s3 zend-framework bucket

最近几天我一直在与之抗争,但我绝望。

我使用Zend S3 lib通过IAM帐户访问我的S3。 我能够列出并创建存储桶,但是我无法放置任何对象,也无法读取通过控制台上传的示例文件的信息($ s3-> getInfo())。 我将我的IAM帐户设置为完全访问权限:AmazonS3FullAccess,还添加了自己的帐户:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "VisualEditor0",
        "Effect": "Allow",
        "Action": [
            "s3:GetAccessPoint",
            "s3:PutAccountPublicAccessBlock",
            "s3:GetAccountPublicAccessBlock",
            "s3:ListAllMyBuckets",
            "s3:ListAccessPoints",
            "s3:ListJobs",
            "s3:CreateJob",
            "s3:HeadBucket"
        ],
        "Resource": "*"
    },
    {
        "Sid": "VisualEditor1",
        "Effect": "Allow",
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::*",
            "arn:aws:s3:*:*:accesspoint/*",
            "arn:aws:s3:*:*:job/*"
        ]
    },
    {
        "Sid": "VisualEditor2",
        "Effect": "Allow",
        "Action": "s3:*",
        "Resource": "arn:aws:s3:::*/*"
    }
]

}

这是我的PHP代码:

    $amazonKey = AWS_ACCESS_KEY;
    $amazonSecret = AWS_SECRET_ACCESS_KEY;

    $s3 = new Zend_Service_Amazon_S3($amazonKey, $amazonSecret);

    //Avaliable buckets this code works:
    $this->view->content.="-----------Avaliable buckets:-------------<br>";
    foreach($s3->getBuckets() as $bucket)

     $this->view->content.=$bucket."<br>";

      //this doesn't work
     $amazonBucket='map-markers';
     $object=$amazonBucket."/myobject";

    $result=$s3->putObject($object, "somedata");

    if ($result===false) $this->view->content.="putObject: '.$object.' FAIL!";
    else
    $this->view->content.="putObject: ".print_r($result)."<br>";

我还尝试了适用于AWS TAmazonStorageService的C ++构建器库:`

if (s3->UploadObject(BUCKET_NAME,OBJ_NAME,AnsiString("test").BytesOf()),true,0, amzbaPrivate, amzrNotSpecified, ResponseInfo) {

       TVarRec args[1] = {ResponseInfo->StatusMessage};
       Console("UploadObject:Upload to "+AnsiString(BUCKET_NAME)+" "+OBJ_NAME+" OK!");
     }

     else
     {
          TVarRec args[1] = {ResponseInfo->StatusMessage};
          Console(Format(AnsiString("UploadObject Failure! %s"), args, 0));

     }

S3-> UploadObject在ResponseInfo中与“ HTTP 200”一起返回true,但是未创建对象。 存储桶权限如下:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "S3Permissions",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::map-markers/*",
            "arn:aws:s3:::map-markers"
        ]
    }
]

}

此外,我取消了对存储桶的所有公共访问。

我不知道我还能做什么?

致以最诚挚的问候 汤姆

`

0 个答案:

没有答案