PHP致命错误:未捕获错误:在test.php中找不到类'Aws \ Common \ Aws'

时间:2017-01-06 03:40:21

标签: php amazon-web-services sdk

我使用composer方法基于http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html安装了AWS PHP SDK v3。尝试了一个简单的例子,但得到了这个错误:

PHP Fatal error:  Uncaught Error: Class 'Aws\Common\Aws' not found in test.php

代码:

<?php

// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';

use Aws\Common\Aws;

$aws = Aws::factory('./cfg.php');

/* CODE BELOW WORKS FINE BY ITSELF
$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-west-1',
    'credentials' => [
        'key'    => '***',
        'secret' => '***'
    ],
]);

$result = $s3->listBuckets();

foreach ($result['Buckets'] as $bucket) {
    // Each Bucket value will contain a Name and CreationDate
    echo "{$bucket['Name']} - {$bucket['CreationDate']}\n";
}
*/
?>

我的PHP版本:

PHP 7.1.0alpha2 (cli) (built: Jun 27 2016 22:39:02) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

我尝试包括aws.phar,但仍然无效。

1 个答案:

答案 0 :(得分:1)

不确定./cfg.php包含哪些内容,但是如果您按照注释后的代码进行操作。

您可以使用Aws\Kms\KmsClient并执行以下操作:

require 'vendor/autoload.php';

$client = Aws\Kms\KmsClient::factory(/*Config Array or Guzzle Http Client*/);

$result = $client->listKeys();

您知道,Aws\Kms\KmsClient几乎与Aws\AwsClient

完全相同

Further info on that config needed to create the client