我正在尝试连接到AWS S3存储桶,并列出存储桶中的每个对象。
当我转到页面时,出现500错误,提示:
Object of class Generator could not be converted to string
我确认我的IAM凭据正确,并且存储桶中有很多对象。
这是我的代码:
//Include the AWS SDK using the Composer autoloader.
require 'awssdk/aws-autoloader.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
// AWS Info
$bucketName = 'pipedemail';
$IAM_KEY = '*****';
$IAM_SECRET = '******';
// Connect to AWS
try {
// and on creation. us-east-2 is Ohio, us-east-1 is North Virgina
$s3 = S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
),
'version' => 'latest',
'region' => 'us-east-1'
)
);
} catch (Exception $e) {
// We use a die, so if this fails. It stops here. Typically this is a REST call so this would
// return a json object.
die("Error: " . $e->getMessage());
}
// Use the high-level iterators (returns ALL of your objects).
$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucketName));
抛出500错误的行是:
$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucketName));
我不知道该如何解决。