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.
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);
});