5

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?

1
  • This sample looks fine, assuming you have set the bucket and key/secret to their actual values. You might consider submitting an issue to the SDK team so we can help you work through this. It would also be a good idea to get a wire log of the request, which will help the SDK team with determining the problem. Commented Jan 7, 2015 at 16:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.