【发布时间】:2021-04-26 14:10:25
【问题描述】:
这是我的代码:
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
define('AWS_KEY', '****');
define('AWS_SECRET_KEY', '****');
// Instantiate the S3 class and point it at the desired host
$client = S3Client::factory(array(
'region' => 'us-east-1',
'version' => 'latest',
'endpoint' => "https://website.com",
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
],
// Set the S3 class to use objects.dreamhost.com/bucket
// instead of bucket.objects.dreamhost.com
'use_path_style_endpoint' => true
));
$listResponse = $client->listBuckets();
print_r($listResponse);
$buckets = $listResponse['Buckets'];
foreach ($buckets as $bucket) {
echo $bucket['Name'] . "\t" . $bucket['CreationDate'] . "\n";
}
这是我得到的回复:
Aws\Result 对象 ( [数据:Aws\Result:private] => 数组 ( [@metadata] => 数组 ( [状态代码] => 200 [有效Uri] => https://website.com/ [标题] => 数组 ( [服务器] => nginx/1.16.1 [日期] => 格林威治标准时间 2021 年 1 月 22 日星期五 04:57:56 [内容类型] => 文本/html;字符集=UTF-8 [传输编码] => 分块 [连接] => 保持活动状态 [x-xss-保护] => 1;模式=块 [x-frame-options] => SAMEORIGIN [x-content-type-options] => nosniff [expect-ct] => 强制执行,max-age=300,report-uri='https://www.website.com' [x-cache] => 旁路 [严格传输安全] => 最大年龄=31536000 )
[transferStats] => Array
(
[http] => Array
(
[0] => Array
(
)
)
)
)
)
[monitoringEvents:Aws\Result:private] => Array
(
)
)
我似乎无法显示存储桶(我目前在 Amazon S3 上的存储桶上)。
关于为什么它不会显示的任何建议?先谢谢了。
【问题讨论】:
-
检查访问密钥策略是否有读或列出bucket的权限?
-
是的,它似乎可以访问
-
你到底想做什么?
-
我只是想列出我的存储桶。
标签: php amazon-web-services amazon-s3