duangan4070 2017-01-06 03:40
浏览 266
已采纳

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

I installed AWS PHP SDK v3 based on http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html using composer method. Tried a simple example but getting this error:

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

Code:

<?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']}
";
}
*/
?>

My PHP version:

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

I tried including aws.phar instead but still did not work.

  • 写回答

1条回答 默认 最新

  • dongzi0850 2017-01-06 04:09
    关注

    Not sure what ./cfg.php contains, but if you follow your commented code.

    You could use Aws\Kms\KmsClient and do something like:

    require 'vendor/autoload.php';
    
    $client = Aws\Kms\KmsClient::factory(/*Config Array or Guzzle Http Client*/);
    
    $result = $client->listKeys();
    

    Just so you know, Aws\Kms\KmsClient is nearly the exact same client as Aws\AwsClient

    Further info on that config needed to create the client

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵