I am new to Amazon S3 and tested several different code examples with Amazon S3, but it is not working. Have tried to keep it as simple as possible. In the example below, I try to list all objects in my bucket.
<?php
require 'includes/aws.phar';
use Aws\S3\S3Client;
$bucket = '*** Bucket Name ***';
// Instantiate the S3 client with your AWS credentials
$s3 = S3Client::factory(array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
));
$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucket));
echo "Keys retrieved!\n";
foreach ($objects as $object) {
echo $object['Key'] . "\n";
}
?>
Error message
Keys retrieved!
Fatal error: Uncaught Aws\S3\Exception\AccessDeniedException: AWS Error Code: AccessDenied, Status Code: 403, AWS Request ID: 34CD33C789DF53E7, AWS Error Type: client, AWS Error Message: Access Denied, User-Agent: aws-sdk-php2/2.7.12 Guzzle/3.9.2 curl/7.30.0 PHP/5.5.6 ITR thrown in phar://C:/xampp/htdocs/amazon-s3-fineupload/view/includes/aws.phar/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91
When I tested with a code sample for pre-signed URL, I got an error message that my generated signature does not match their
I have not made any settings on amazon. Do I need to add something in policy? I have checked my keys (key and secret) and they are correct! Same with my bucket-name.
Can someone please give me a working example in PHP, as showing a file on S3 and tell me if I need to make some settings on S3?
Aucun commentaire:
Enregistrer un commentaire