1
votes

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

1
That's weird. Accessing the URL directly returns 200OK: curl -I storage/novybucket?encoding-type=url HTTP/1.1 200 OK Date: Fri, 27 Mar 2020 12:34:51 GMT Server: RestServer/1.0 Content-Type: binary/octet-stream Cache-Control: no-cache Connection: closeLukáš H.
Did you ever come up with a fix for this? Having the same issue.swift--help

1 Answers

0
votes

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.