Error retrieving credentials from the instance profile metadata server.Failed to connect to 169.254.169.254 port 80: No route to host
Asked Answered
B

2

8

I am trying to create a sub-domain using Route53 with aws-php-sdk.

but I am getting this error again and again:

[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

I am using aws-sdk-php version: 3.29 "aws/aws-sdk-php": "^3.29"

Here is my written code

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 
                            ), 
                        ),
                    ),
                ),
          ),
    ));

Help will be appreciable. Thanks in advance.

Bainite answered 16/6, 2017 at 10:23 Comment(0)
P
7

This question is very old but I want to drop an answer in case someone has a similar issue.

The AWS PHP SDK needs credentials to communicate with AWS. the credentials are known as access key ID and secret access key.

As highlighted in AWS documentation

If you do not provide credentials to a client object at the time of its instantiation, the SDK will attempt to find credentials in your environment.

According to your logs it seems that the SDK is still pulling credentials from your environment which are stored in ~/.aws/credentials, and not using the provided keys.

Either make sure you have the access key and the secret key in your environment variable.

$ less ~/.aws/credentials

[default]
aws_access_key_id = key
aws_secret_access_key = secret

Or

Clear the configuration cache to force using the explicit credentials declared in the instantiation of your client. in case they were cached.

php artisan config:cache

Also refer to this documentation on how to properly setup a client.

https://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html

Population answered 22/1, 2018 at 13:42 Comment(0)
D
0

If you use php artisan config:cache make sure you don't use env() helper for accessing env variables from anywhere except the config files (config/*). Avoid using env() helper in your blade templates. This is because, calling env() helper after the above command is run, will return null.

Instead use a config file for accessing env values. If a separate config file under the config folder is not available for that vendor package / service, The config/services.php is a good place to point to env values.

Thephp artisan config:cache command will speed up your app as the the env variables are cached and so is recommended in a production environment.

Refer Laravel Configuration Caching for more details.

Dettmer answered 28/4, 2018 at 4:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.