简体   繁体   中英

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

I'm fully aware that S3 is region agnostic and that it shouldn't matter that the rest of our system is in us-east-2, but...

If I try to initialize without a signature or regionm it tells me that I'm now required to use the v4 signature:

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

I try to initialize S3 without a region:

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

Alright that makes sense, I guess I have to supply a region even though S3 doesn't require a region...

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

Oh... oh... ok. I guess I need to use us-east-2 since the rest of our servers and services are built on 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

Then why would you tell me to use us-east-2 AWS?!?

My aws.phar is version 2.6.15.

This was a known issue with AWS PHP SDK in 2.xx versions. You will need to upgrade the SDK to 2.8.x and above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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