php - aws s3 sdk php 在 getObjects 时遇到永久重定向

标签 php amazon-web-services amazon-s3 aws-sdk

我是 AWS s3 的新手,试图弄清楚如何在 php 中使用它。
我开始使用并且我可以使用 s3->listBuckets 方法列出我的所有存储桶,但是当我尝试列出此存储桶中的所有对象时,它失败了

PHP Fatal error: Uncaught Aws\S3\Exception\PermanentRedirectException: Encountered a permanent redirect while requesting https://s3.us-east-2.amazonaws.com/ischool.simplein?encoding-type=url. Are you sure you are using the correct region for this bucket? in /Users/momen/Desktop/studio/s3/sdk/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php:49 Stack trace:



关键是,我拥有的凭据是用于 us-west-2 帐户的,但是当我创建 s3 存储桶时,我选择将它托管在 eu-london。

复制问题的示例代码。
require('vendor/autoload.php');
// Use the us-west-2 region and latest version of each client.

$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-east-2',
    'credentials' => [
        'key'    => AWS_KEY,
        'secret' => AWS_SECRET
    ]
]);


$buckets = $s3->listBuckets(); // works
$bucket = $buckets['Buckets'][1]['Name'];

$objects = $s3->listObjects([ 'Bucket' => $bucket ]) // FAIL with permenant redirect

那么我应该使用哪个地区?为什么我可以列出存储桶,但不能使用它们?

最佳答案

所以第一个问题:

Which region should i use?



您应该使用区域 eu-west-2
Here是所有地区文档的链接。

现在来回答另一个问题:

How to utilize buckets?



这个错误看起来很明显,你有错误的区域。所以我会考虑改变地区,然后再试一次。

这是另一个相关问题:Amazon S3 Upload error PermanentRedirectException

关于php - aws s3 sdk php 在 getObjects 时遇到永久重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48801810/

相关文章:

php - 在 PHP 中对表中的数据进行分组

php - Yii 2 分页无法正常工作

json - 发行 “Accessing S3 bucket from ElasticBeanstalk using Docker Json file”

amazon-web-services - 在 Amazon CloudFront 中为特定文件类型添加内容类型?

php - 如何为注销和登录用户显示不同的WordPress首页?

php - strcmp 在 PHP 中未按预期工作

amazon-web-services - DynamoDb 查询仅通过主键

amazon-web-services - AWS Glue Crawler 创建分区和文件表

spring - 不能在 Spring AWS 示例上强制转换为 org.springframework.core.io.WritableResource

angularjs - AWS S3 NodeJS 禁止或连接休息