Can';t使用PHP获取要显示的S3存储桶
这是我的密码:Can';t使用PHP获取要显示的S3存储桶,php,amazon-web-services,amazon-s3,Php,Amazon Web Services,Amazon S3,这是我的密码: 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',
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]=>数组
(
[@元数据]=>数组
(
[状态代码]=>200
[有效URI]=>
[标题]=>数组
(
[服务器]=>nginx/1.16.1
[日期]=>2021年1月22日星期五04:57:56 GMT
[内容类型]=>text/html;字符集=UTF-8
[传输编码]=>分块
[连接]=>保持活动状态
[x-xss-protection]=>1;模式=块
[x-frame-options]=>SameOrgin
[x-content-type-options]=>nosniff
[expect ct]=>enforce,最大年龄=300,报告uri=>https://www.website.com'
[x-cache]=>旁路
[严格的运输安全]=>最大年龄=31536000
)
我似乎无法让bucket出现(我目前在AmazonS3上的bucket上有)
关于它为什么不显示有什么建议吗?非常感谢。我可以使用下面的代码获得bucket列表。唯一的区别是我在创建S3客户端对象时没有使用endpoint
<?php
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
* the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* ABOUT THIS PHP SAMPLE: This sample is part of the SDK for PHP Developer Guide topic at
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-examples-creating-buckets.html
*
*/
// snippet-start:[s3.php.list_buckets.complete]
// snippet-start:[s3.php.list_buckets.import]
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
// snippet-end:[s3.php.list_buckets.import]
/**
* List your Amazon S3 buckets.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
//Create a S3Client
// snippet-start:[s3.php.list_buckets.main]
define('AWS_KEY', '*****');
define('AWS_SECRET_KEY', '***************');
// Instantiate the S3 class and point it at the desired host
$s3Client = S3Client::factory(array('credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
],'region' => 'us-east-1','version' => 'latest'));
//Listing all S3 Bucket
$buckets = $s3Client->listBuckets();
foreach ($buckets['Buckets'] as $bucket) {
echo $bucket['Name'] . "\n";
}
检查访问密钥策略是否具有读取或列出存储桶的权限?是的,它似乎具有访问权限您到底想做什么?我只是尝试列出我的存储桶。这很有效-我不确定有什么不同,但谢谢!
<?php
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
* the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* ABOUT THIS PHP SAMPLE: This sample is part of the SDK for PHP Developer Guide topic at
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-examples-creating-buckets.html
*
*/
// snippet-start:[s3.php.list_buckets.complete]
// snippet-start:[s3.php.list_buckets.import]
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
// snippet-end:[s3.php.list_buckets.import]
/**
* List your Amazon S3 buckets.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
//Create a S3Client
// snippet-start:[s3.php.list_buckets.main]
define('AWS_KEY', '*****');
define('AWS_SECRET_KEY', '***************');
// Instantiate the S3 class and point it at the desired host
$s3Client = S3Client::factory(array('credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
],'region' => 'us-east-1','version' => 'latest'));
//Listing all S3 Bucket
$buckets = $s3Client->listBuckets();
foreach ($buckets['Buckets'] as $bucket) {
echo $bucket['Name'] . "\n";
}