I am using Laravel 5.4 with aws-sdk-php version: 3.29
[2017-06-16 12:17:00] local.ERROR: Aws\Exception\CredentialsException: Error retrieving credentials from the instance profile metadata server.
(cURL error 7: Failed to connect to 169.254.169.254 port 80: No route to host (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)) in /var/www/html/test/vendor/aws/aws-sdk-php/src/Credentials/InstanceProfileProvider.php:79
use Aws\Route53\Route53Client;
$client = Route53Client::factory(array(
'region' => 'us-east-1',
'version' => '2013-04-01',
'credentials ' => array('key'=>'AWS_KEY',
'secret'=>'AWS_SECRET_KEY')
));
$result = $client->changeResourceRecordSets(array(
// HostedZoneId is required
'HostedZoneId' => 'ROUTER_53_HOSTED_ZONE_ID',
// ChangeBatch is required
'ChangeBatch' => array(
// Changes is required
'Changes' => array(
array(
// Action is required
'Action' => 'CREATE',
// ResourceRecordSet is required
'ResourceRecordSet' => array(
// Name is required
'Name' => 'test2.xyz.co.in.',
// Type is required
'Type' => 'A',
'TTL' => 600,
"AliasTarget"=> array(
"HostedZoneId"=> "LOAD_BALANCER_ZONE_ID",
"DNSName"=> "LOAD_BALANCER_DOMAIN_NAME",
"EvaluateTargetHealth"=> false
),
),
),
),
),
));
@tarunkumar2215 Are you running this on an EC2 machine or a different host?
I am running this code in localhost.
@tarunkumar2215 It looks like you have whitespace in your credentials array key: 'credentials ' should be 'credentials', notably without the two spaces.
Fixed this issue. Here is the code below.
$client = AWS::createClient('Route53');
$result = $client->changeResourceRecordSets([
'ChangeBatch' => [
'Changes' => [
[
'Action' => 'CREATE',
'ResourceRecordSet' => [
'AliasTarget' => [
'DNSName' => HOSTED_ZONE_DNSNAME_LB,
'EvaluateTargetHealth' => false,
'HostedZoneId' => HOSTED_ZONE_ID_LB,
],
// Name is required
'Name' => 'test2.xyz.co.in.',
// Type is required
'Type' => 'A',
],
],
],
'Comment' => 'Creating new Route',
],
'HostedZoneId' => HOSTED_ZONE_ID_R53, // Depends on the type of resource that you want to route traffic to
]);
It looks like you went the route of just removing the specified credentials to solve the issue. For later reference, see the Credentials guide for the SDK here.
Closing as reported fixed.
Still doesnt work
I am using AWS elastic beanstalk
Why does it try to read credentials from /.aws/credentials ??
I provided hard coded credentials in this format
'profile' => 'default',
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => [
'key' => 'key',
'secret' => 'secret',
],
still the same error.
Created environment variables in aws beanstalk with AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, it still didnt work (same error).
PHP Fatal error: Uncaught Aws\\Exception\\CredentialsException: Cannot read credentials from
/.aws/credentials in /var/app/current/symfony/vendor/aws/aws-sdk-php/src/Credentials/CredentialProvider.php:394\nStack trace:\n#0 /var/app/current/symfony/vendor/aws/aws-sdk-php/src/Credentials/CredentialProvider.php(290): Aws\\Credentials\\CredentialProvider::reject('Cannot read cre...')\n#1 /var/app/current/symfony/vendor/aws/aws-sdk-php/src/Middleware.php(121): Aws\\Credentials\\CredentialProvider::Aws\\Credentials\\{closure}()\n#2 /var/app/current/symfony/vendor/aws/aws-sdk-php/src/RetryMiddleware.php(192): Aws\\Middleware::Aws\\{closure}(Object(Aws\\Command), Object(GuzzleHttp\\Psr7\\Request))\n#3 /var/app/current/symfony/vendor/aws/aws-sdk-php/src/Middleware.php(206): Aws\\RetryMiddleware->__invoke(Object(Aws\\Command), Object(GuzzleHttp\\Psr7\\Request))\n#4 /var/app/current/symfony/vendor/aws/aws-sdk-php/src/ClientResolver.php(584): Aws\\Middleware::Aws\\{closure}(Object(Aws\\Command), Object(GuzzleHttp\\Psr7\\Request))\n#5 /var/app/current/symfony/vendor/ in /var/app/current/symfony/vendor/aws/aws-sdk-php/src/Credentials/CredentialProvider.php on line 394, referer: http://qbil-dev.us-west-2.elasticbeanstalk.com/
@faizanakram99
You can do the following:
$credentials = new Aws\Credentials\Credentials(AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY);
array(
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => $credentials
)
It looks like you went the route of just removing the specified credentials to solve the issue. For later reference, see the Credentials guide for the SDK here.
Closing as reported fixed.
The Credentials guide for SDK wasn't terribly helpful in this regard. According to the guide, tarunkumar2215's initial config should have worked.
Thanks @raoabid this solved my problem. And I agree with @chrisostrom . They need better documentation.
We are getting the same error and this doesn't work in my case where we don't have any AWS credentials present inside of the host. We have simply assigned it an instance role ... and we keep getting this error message.
Same, getting this error when using an assigned instance role
Most helpful comment
@faizanakram99
You can do the following:
$credentials = new Aws\Credentials\Credentials(AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY);
array(
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => $credentials
)