通过PHP SDK实现S3客户端初始化错误

Adr*_*lls 4 php amazon-s3 amazon-web-services aws-sdk

我正在尝试从AWS PHP SDK初始化S3客户端.我的代码如下:

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

$s3_client = new S3Client([
    'version'     => 'latest',
    'region'      => $region,
    'credentials' => $credentials
]);
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

遇到PHP错误

严重程度:4096

消息:传递给Aws\Common\Client\AbstractClient :: __ construct()的参数1必须实现接口Aws\Common\Credentials\CredentialsInterface,给定的数组,在/ opt/showhouse/www/application/models/showhouse/common/services中调用第47行/aws/aws.php并定义了Filename:Client/AbstractClient.php

行号:73

我出错的任何想法?我使用的是通过Composer安装的最新版本的SDK.

小智 6

我猜你正在使用AWS PHP SDK 2.0版.如果是这样,那么S3Client确实实现了AbstractClient类.这意味着参数是:__ construct(Aws\Common\Aws\Common\Credentials\CredentialsInterface $ credentials,Aws\Common\Aws\Common\Signature\SignatureInterface $ signature,Guzzle\Common\Collection $ config)

您尝试使用的S3Client实现来自AWS PHP SDK的3.0版.