繁体   English   中英

如何在us-east-2中列出存储桶的AWS S3文件?

[英]How do I list AWS S3 files for a bucket in us-east-2?

我完全知道S3是区域不可知的,并且我们系统的其余部分在us-east-2中都没有关系,但是...

如果我尝试不使用签名或regionm进行初始化,则会告诉我现在需要使用v4签名:

php > $s3Client = \Aws\S3\S3Client::factory(array('key' => 'ACCESS', 'secret' => 'SECRET', 'version' => '2006-03-01'));
php > $objects = $s3Client->getListObjectsIterator(array('Bucket'=>'my-bucket')); foreach ($objects as $object) { echo $object['Key'] . "\n"; };

Warning: Uncaught Aws\S3\Exception\InvalidRequestException: AWS Error Code: InvalidRequest, Status Code: 400, AWS Request ID: REQUEST, AWS Error Type: client, AWS Error Message: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256., User-Agent: aws-sdk-php2/2.7.0 Guzzle/3.9.2 curl/7.54.0 PHP/7.1.23 ITR
  thrown in phar:///Library/WebServer/lib/aws.phar/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

我尝试初始化没有区域的S3:

php > $s3Client = \Aws\S3\S3Client::factory(array('key' => 'ACCESS', 'secret' => 'SECRET', 'signature' => 'v4'));

Warning: Uncaught Aws\Common\Exception\InvalidArgumentException: A region must be specified when using signature version 4 in phar:///Library/WebServer/aws.phar/Aws/S3/S3Client.php:283
Stack trace:
#0 phar:///Library/WebServer/aws.phar/Aws/S3/S3Client.php(171): Aws\S3\S3Client::createSignature(Array)
#1 php shell code(1): Aws\S3\S3Client::factory(Array)
#2 {main}
  thrown in phar:///Library/WebServer/aws.phar/Aws/S3/S3Client.php on line 283

好吧,我想我必须提供一个区域,即使S3不需要区域...

php > $s3Client = \Aws\S3\S3Client::factory(array('key' => 'ACCESS', 'secret' => 'SECRET', 'signature' => 'v4', 'region' => 'us-east-1'));
php > $objects = $s3Client->getListObjectsIterator(array('Bucket'=>'my-bucket', 'Region' => 'us-east-1')); foreach ($objects as $object) { echo $object['Key'] . "\n"; };

Warning: Uncaught Aws\S3\Exception\S3Exception: AWS Error Code: AuthorizationHeaderMalformed, Status Code: 400, AWS Request ID: REQUEST, AWS Error Type: client, AWS Error Message: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'us-east-2', User-Agent: aws-sdk-php2/2.6.15 Guzzle/3.9.2 curl/7.54.0 PHP/7.1.23 ITR
  thrown in phar:///Library/WebServer/aws.phar/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

哦哦好的 我想我需要使用us-east-2,因为我们其余的服务器和服务都建立在us-east-2上。

php > $s3Client = \Aws\S3\S3Client::factory(array('key' => 'ACCESS', 'secret' => 'SECRET', 'signature' => 'v4', 'region' => 'us-east-2'));

Warning: Uncaught Aws\Common\Exception\InvalidArgumentException: us-east-2 is not a valid region for Amazon Simple Storage Service in phar:///Library/WebServer/aws.phar/Aws/Common/Client/AbstractClient.php:131
Stack trace:
#0 phar:///Library/WebServer/aws.phar/Aws/Common/Client/ClientBuilder.php(394): Aws\Common\Client\AbstractClient::getEndpoint(Object(Guzzle\Service\Description\ServiceDescription), 'us-east-2', 'https')
#1 phar:///Library/WebServer/aws.phar/Aws/Common/Client/ClientBuilder.php(204): Aws\Common\Client\ClientBuilder->updateConfigFromDescription(Object(Guzzle\Common\Collection))
#2 phar:///Library/WebServer/aws.phar/Aws/S3/S3Client.php(207): Aws\Common\Client\ClientBuilder->build()
#3 php shell code(1): Aws\S3\S3Client::factory(Array)
#4 {main}
  thrown in phar:///Library/WebServer/aws.phar/Aws/Common/Client/AbstractClient.php on line 131

那你为什么要告诉我使用us-east-2 AWS?!?

我的aws.phar是2.6.15版。

这是2.xx版本的AWS PHP SDK的一个已知问题。 您需要将SDK升级到2.8.x及更高版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM