简体   繁体   English

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

[英]S3 client initialization error via PHP SDK

I'm trying to initialize the S3 client from the AWS PHP SDK. 我正在尝试从AWS PHP SDK初始化S3客户端。 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 遇到PHP错误

Severity: 4096 严重程度: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 消息:传递给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

Line Number: 73 行号:73

Any ideas where I am going wrong? 我出错的任何想法? Am using the latest version of the SDK installed via Composer. 我使用的是通过Composer安装的最新版本的SDK。

I'm guessing you are using AWS PHP SDK version 2.0. 我猜你正在使用AWS PHP SDK 2.0版。 If so, then the S3Client indeed implements the AbstractClient class. 如果是这样,那么S3Client确实实现了AbstractClient类。 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 ) 这意味着参数是:__ 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. 您尝试使用的S3Client实现来自AWS PHP SDK的3.0版。

Recommendation: Try using a downloaded zip file to install AWS SDK instead of Composer 建议:尝试使用下载的zip文件来安装AWS SDK而不是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. 当我使用Composer安装AWS SDK时,我遇到了同样的问题,因为它似乎是来自以下URL的AWS文档中的推荐方法。

https://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html 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. 但是,在阅读Grilly的有用答案后,我决定尝试使用下载的zip文件来安装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. 从zip文件中包含的README文件中,我可以找到使用下载的zip文件安装的AWS SDK版本为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. 虽然我无法检查使用Composer安装的AWS SDK的版本,因为我找不到如何,我猜测使用Composer安装的AWS SDK版本有点老,足以导致问题。

我有同样的问题,并通过使用PHP 5.6与AWS SDK v3.x修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM