OS: Mojave (Mac)
AWS SDK 3
我的代码
<?php
require AWS_JHM_INCLUDE.'aws-autoloader.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
use Aws\Polly\Exception\PollyException;
use Aws\Polly\PollyClient;
$credentials = array (
'version' => 'latest',
'region' => 'us-east-2a',
'profile' => 'my_default',
'credentials' => array(
'key' => 'xxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxx'
)
);
$bucket_name = 'my_test';
$s3client = new S3Client($credentials);
echo 'Client created';
create_s3_bucket($s3client, $bucket_name);
function create_s3_bucket($s3Client, $bucket_name)
{
try {
$result = $s3Client->createBucket(array('Bucket' => $bucket_name));
} catch (AwsException $ex) {
echo($e->getMessage());
}
}
运行它时,我看到:
Client created
随后出现此错误:
Fatal error:
Uncaught Aws\Exception\CredentialsException: Cannot read credentials from /Users/jjm/.aws/credentials in /Users/jjm/Dropbox/Development/php/aws/Aws/Credentials/CredentialProvider.php:399 Stack trace: #0 /Users/jjm/Dropbox/Development/php/aws/Aws/Credentials/CredentialProvider.php(295): Aws\Credentials\CredentialProvider::reject('Cannot read cre...') #1 /Users/jjm/Dropbox/Development/php/aws/Aws/Middleware.php(121): Aws\Credentials\CredentialProvider::Aws\Credentials\{closure}() #2 /Users/jjm/Dropbox/Development/php/aws/Aws/RetryMiddleware.php(264): Aws\Middleware::Aws\{closure}(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request)) #3 /Users/jjm/Dropbox/Development/php/aws/Aws/Middleware.php(206): Aws\RetryMiddleware->__invoke(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request)) #4 /Users/jjm/Dropbox/Development/php/aws/Aws/S3/S3EndpointMiddleware.php(102): Aws\Middleware::Aws\{closure}(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request)) #5 /Users/jjm/Dropbox/ in /Users/jjm/Dropbox/Development/php/aws/Aws/Credentials/CredentialProvider.php on line 399
因此,当我尝试创建存储桶时会生成错误。我已经在本地定义了凭据,那么SDK为什么要在其他地方寻找凭据?