duanjiong5023 2015-01-05 22:32
浏览 150

使用PHP和S3 SDK连接到Amazon S3有什么问题?

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!
";
foreach ($objects as $object) {
    echo $object['Key'] . "
";
}

?>

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统