2017-03-04 2 views
0

Ich versuche, eine Datei zu AWS S3 Eimer über php sdk zu laden, um das zu tun, dass ich eine IAM-Benutzer erstellt haben und hinzugefügt, um eine Inline-PolitikAWS S3: Zugriff verweigert, während Datei hochladen

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
      "Effect": "Allow", 
      "Action": [ 
       "s3:ListBucket", 
       "s3:GetBucketLocation" 
      ], 
      "Resource": "arn:aws:s3:::bucket/*" 
     }, 
     { 
      "Effect": "Allow", 
      "Action": [ 
       "s3:PutObject", 
       "s3:GetObject", 
       "s3:DeleteObject" 
      ], 
      "Resource": "arn:aws:s3:::bucket/*" 
     } 
    ] 
} 

hier ist meine pHP-Code

$s3 = new S3Client([ 
    'version' => 'latest', 
    'region' => 'ap-south-1', 
    'credentials' => 
     array(
      'key'=>'X', 
      'secret' =>'X' 
     ) 
]); 

try { 
    $s3->putObject([ 
     'Bucket' => 'candy-prototype', 
     'Key' => 'my-object.txt', 
     'Body' => fopen('test.txt', 'r'), 
     'ACL' => 'public-read', 
    ]); 
} catch (Aws\S3\Exception\S3Exception $e) { 
    echo $e->getMessage(); 
    echo "There was an error uploading the file.\n"; 
} 

Aber es wird geworfen Zugriff verweigert Ausnahme

Error executing "PutObject" on "https://s3.<region>.amazonaws.com/bucket/my-object.txt"; AWS HTTP 

error: Client error: PUT https://s3.ap-south-1.amazonaws.com/candy-prototype/my-object.txt resulted in a 403 Forbidden response: AccessDeniedAccess DeniedC21D9D (truncated...) AccessDenied (client): Access Denied - AccessDeniedAcces UPDATE

Zugegeben lesen und schreiben Permissi an everyone aber es hat nicht funktioniert. IAM Benutzer kann in der Lage zu laden/löschen/Blick von aws Web-Adminpanel, aber der api Zugriff verweigert

Antwort

1

ListBucket & GetBucketLocation zu Eimer angewendet werden sollte, nicht bucket/* Ändern der Ressource in dem ersten Teil die Politik

{ 
     "Effect": "Allow", 
     "Action": [ 
      "s3:ListBucket", 
      "s3:GetBucketLocation" 
     ], 
     "Resource": "arn:aws:s3:::bucket" 
    }, 

this Dokumentation

siehe
Verwandte Themen