我正在尝试通过使用AWS凭据文件连接到amazon s3,因为我已经完成了以下事情
我在credentials.ini
创建了.aws\credentials
个文件。它有效AWSAccessKeyId
和AWSSecretKey
[default]
AWSAccessKeyId=somekey
AWSSecretKey=somesecretkey
我正在使用密钥并列出所有对象
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-west-2'
]);
$result = $s3->listBuckets();
var_dump($result);
我收到错误
Warning: parse_ini_file(C:\Users\user\.aws\credentials): failed to open stream: Permission denied in C:\xampp\htdocs\aws\vendor\aws\aws-sdk-php\src\Credentials\CredentialProvider.php on line 216
Fatal error: Uncaught exception 'Aws\Exception\CredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. (cURL error 28: Connection timed out after 1000 milliseconds (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))' in C:\xampp\htdocs\aws\vendor\aws\aws-sdk-php\src\Credentials\InstanceProfileProvider.php:79 Stack trace: #0 C:\xampp\htdocs\aws\vendor\guzzlehttp\promises\src\Promise.php(199): Aws\Credentials\InstanceProfileProvider->Aws\Credentials\{closure}(Array) #1 C:\xampp\htdocs\aws\vendor\guzzlehttp\promises\src\Promise.php(152): GuzzleHttp\Promise\Promise::callHandler(2, Array, Array) #2 C:\xampp\htdocs\aws\vendor\guzzlehttp\promises\src\TaskQueue.php(60): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() #3 C:\xampp\htdocs\aws\vendor\guzzlehttp\guzzle\src\Handler\CurlMultiHandler.php(96): GuzzleHttp\Promise\TaskQueue->run() #4 C:\xampp\htdocs\aws\vendor\guzzlehttp\guzzle\src\Handler\CurlMultiHandler.php(123): GuzzleHttp\Handler\CurlMultiHandler->tick in C:\xampp\htdocs\aws\vendor\aws\aws-sdk-php\src\Credentials\InstanceProfileProvider.php on line 79
答案 0 :(得分:2)
根据AWS PHP documentation,凭证文件的格式如下:
[default]
aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
在你的情况下,我认为这是正在发生的事情:
您可以在source code for the AWS PHP library中清楚地看到所有这些内容。
最终结果是,第3步失败了,但实际上步骤#1,#2和#3失败了。所以,我认为修复就像纠正INI文件中的键名一样简单。