简体   繁体   中英

S3 API - aws-php-sdk - AuthMethodNotRecognized

I need help with S3 API using official aws-sdk-php and connecting to third party S3 compatible storage. Aws-sdk-php is installed using composer.

I am getting 403 all the time and response from server: AuthMethodNotRecognized

Any ideas please?


use Aws\S3\S3Client;

define('AWS_KEY', username');

define('AWS_SECRET_KEY', 'password);

$ENDPOINT = 'http://storage';

require __DIR__.'/vendor/autoload.php';

$client = new S3Client([

'region' => '',

'version' => 'latest',

//'version' => '2006-03-01',

'endpoint' => $ENDPOINT,

'credentials' => [

'key' => AWS_KEY,

'secret' => AWS_SECRET_KEY

],

'use_path_style_endpoint' => true

]);



$bucketname = "novybucket";

$objectsListResponse = $client->listObjects(['Bucket' => $bucketname]);

$objects = $objectsListResponse['Contents'] ?? [];

foreach ($objects as $object) {

    echo $object['Key'] . "\t" . $object['Size'] . "\t" . $object['LastModified'] . "\n";

}

Fatal error: Uncaught exception 'Aws\\S3\\Exception\\S3Exception' with message 'Error executing "ListObjects" on " https://storage/novybucket?encoding-type=url "; AWS HTTP error: Client error: GET https://storage/novybucket?encoding-type=url resulted in a 403 Forbidden response: AuthMethodNotRecognized AuthMethodNotRecognized (client): - AuthMethodNotRecognized ' GuzzleHttp\\Exception\\ClientException: Client error: GET https://storage/novybucket?encoding-type=url resulted in a 403 Forbidden response: AuthMethodNotRecognized in /var/www/html/lukas/s3/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/html/lukas/s3/vendor/guzzlehttp/guzzle/src/Middleware.php in /var/www/html/lukas/s3/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 195

Looks it has something to do with sigv3 vs sigv2. Anyway I am not sure how to change it using SDK, tried to simulate it using s3cmd where it works when specifying to use sigv2.

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