6

I'm trying to initialize the S3 client from the AWS PHP SDK. My code is as follows:

$credentials = new Credentials(self::KEY, self::SECRET);

$s3_client = new S3Client([
    'version'     => 'latest',
    'region'      => $region,
    'credentials' => $credentials
]);

But am getting the following errors:

A PHP Error was encountered

Severity: 4096

Message: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must implement interface Aws\Common\Credentials\CredentialsInterface, array given, called in /opt/showhouse/www/application/models/showhouse/common/services/aws/aws.php on line 47 and defined Filename: Client/AbstractClient.php

Line Number: 73

Any ideas where I am going wrong? Am using the latest version of the SDK installed via Composer.

4 Answers 4

9

I'm guessing you are using AWS PHP SDK version 2.0. If so, then the S3Client indeed implements the AbstractClient class. This means that the parameters are: __construct( Aws\Common\Aws\Common\Credentials\CredentialsInterface $credentials, Aws\Common\Aws\Common\Signature\SignatureInterface $signature, Guzzle\Common\Collection $config )

The S3Client implementation you are attempting to use is from version 3.0 of the AWS PHP SDK.

Sign up to request clarification or add additional context in comments.

Comments

2

Recommendation: Try using a downloaded zip file to install AWS SDK instead of Composer

I had the same problem when I used Composer to install AWS SDK because it appeared to be the recommended way in AWS documentation from the following URL.

https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html

But, after reading the helpful answer by Grilly, I decided to try using a downloaded zip file to install AWS SDK. The problem disappeared after I installed this way.

From a README file contained in the zip file, I could find a notification that the version of AWS SDK installed using the downloaded zip file was 3.0. Although I couldn't check version of AWS SDK installed using Composer because I couldn't find how, I am guessing that the version of AWS SDK installed using Composer was somewhat old enough to cause the problem.

Comments

0

I had the same problem and fixed by using PHP 5.6 with AWS SDK v3.x

Comments

0

If you have problem with credentials: <?php

use Aws\S3\S3Client;
$s3Client = S3Client::factory(array(
    'credentials' => array(
       'key'    => 'AWS_ACCESS_KEY_ID',
       'secret' => 'AWS_SECRET_ACCESS_KEY',
    )
));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.