我使用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,但仍然无效。
答案 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