nova
nova

Reputation: 313

aws ec2 getaddrinfo ENOTFOUND error code

My aim is to get the instanceId when my script is started. (Cause I want to connect my webserver as backend with the aws elb. This even works when I hardcode the id) So now I try to code a function wich gives me the id.

So what I know is that I need the AWS.metadataService but I don't know how to use it. I found this documentation (metaDataService) an command-line tool. I guess I need to combine it like this:

var meta  = new AWS.MetadataService();

meta.request("http://169.254.169.254/latest/meta-data/", function(err, data){
    if(err){
        console.log(err);
    }
    console.log(data);
});

But it produces this error:

{ [Error: getaddrinfo ENOTFOUND 169.254.169.254http 169.254.169.254http:80]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: '169.254.169.254http',
  host: '169.254.169.254http',
  port: 80 }

Any ideas what could fix this? Or at least what causes this error.

Upvotes: 4

Views: 9668

Answers (2)

tripleee
tripleee

Reputation: 189678

As the error message rather clearly tells you, you somehow ended up passing in 169.254.169.254http as the host name, and 169.254.169.254http:80 as the host. Just to spell this out completely, you probably wanted the host to be 169.254.169.254. You need to figure out why your request was botched like this, and correct the code or your configuration files so you send what you wanted to send.

ENOTFOUND in response to getaddrinfo simply means that you wanted to obtain the address of something which doesn't exist or is unknown. Very often this means that you have a typo, or that the information you used to configure your service is obsolete or otherwise out of whack (attempting to reach a private corporate server when you are outside the corporate firewall, for example).

Upvotes: 1

Mukesh Sharma
Mukesh Sharma

Reputation: 9032

Hope it helps.

var meta  = new AWS.MetadataService({
   host: '169.254.169.254'
});

meta.request('/latest/meta-data/', function(err, data){
   if(err){
      console.log(err);
   }
   console.log(data);
});

Upvotes: 5

Related Questions