问题
I am trying to connect to amazon s3 by Using the AWS credentials file for that i have done following things
I have created
credentials.inifile at.aws\credentials. It have validAWSAccessKeyIdandAWSSecretKey[default] AWSAccessKeyId=somekey AWSSecretKey=somesecretkeyI am doing following to use key and list all object
.
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-west-2'
]);
$result = $s3->listBuckets();
var_dump($result);
and i am getting error
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
回答1:
According to the AWS PHP documentation, the format of the credentials file is as follows:
[default]
aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
In your case, here is what I believe is happening:
- first, the PHP library tries to get credentials from the environment, but they are not present so ...
- next, it tries to get them from the INI file, but you have mis-spelled the keys so ...
- finally, it tries to get them from the EC2 metadata server but it looks like you are not running on an EC2 instance so there is no metadata server and that attempt, using curl, times out.
You can see all of this clearly in the source code for the AWS PHP library.
The end result that bubbles up to you is that step #3 failed, but actually steps #1, #2, and #3 failed. So, I think the fix is as simple as correcting the key names in the INI file.
来源:https://stackoverflow.com/questions/31722099/getting-permission-denied-in-amazon-aws