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
php amazon-s3 amazon-web-services


source to share


No one has answered this question yet

Check out similar questions:

4270
Link. What does this symbol mean in PHP?
2776
How can I prevent SQL injection in PHP?
2414
Why shouldn't I use the mysql_ * functions in PHP?
2335
Removing an element from an array in PHP
2024
How do you parse and process HTML / XML in PHP?
1906
How does PHP foreach work?
1065
Link. What does this error mean in PHP?
1004
What is stdClass in PHP?
3
Upload file to amazon S3 using PHP SDK
3
Errors Using PHP SDK for Amazon S3



All Articles
Loading...
X
Show
Funny
Dev
Pics