I try for the first time to use the PHP AWS SDK ("aws/aws-sdk-php": "^3.19") to use S3.
I created a bucket : 'myfirstbucket-jeremyc'
I created a policy :
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject" ], "Resource": [ "arn:aws:s3:::myfirstbucket-jeremyc/*" ] } ] } I applied the policy to a group and then created a user 's3-myfirstbucket-jeremyc' in this group.
My PHP code is :
<?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' )); But i get this error :
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
Do you know where i'm wrong ?
Thanks in advance !