What's wrong with my Amazon S3 connection with PHP and S3 SDK?

I'm new to Amazon S3 and have tested some code examples with Amazon S3 but it doesn't work. We tried to keep it as simple as possible. In the example below, I am trying to list all the 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 sample code for a pre-signed url, I got an error that my generated signature does not match theirs

I have not set any preferences on amazon. Do I need to add something to the policy? I have checked my keys (key and secret) and they are correct! It's the same with my led name.

Can someone please give me a working PHP example showing a file on S3 and tell me if I need to do some customization on S3?

+3


source to share





All Articles