Question:
I’m trying to initialize the S3 client from the AWS PHP SDK. My code is as follows:
1 2 3 4 5 6 7 8 |
$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.phpLine Number: 73
Any ideas where I am going wrong? Am using the latest version of the SDK installed via Composer.
Answer:
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.