Aws-sdk-js: `UnknownEndpoint: Inaccessible host` when launching an EC2 instance.

Created on 16 May 2018  路  5Comments  路  Source: aws/aws-sdk-js

Hello good people of aws-sdk-js,

I am trying to launch a ec2 instance through the sdk but I am unable to do so. It seems that the endpoint is not being properly configured by the sdk.

Problem:

Unable to launch an ec2 through the sdk.

{ UnknownEndpoint: Inaccessible host: `ec2.undefined.amazonaws.com'. This service may not be available in the `eu-west-2' region.
    at Request.ENOTFOUND_ERROR (/Users/alvarogimeno/lab/node/aws/node_modules/aws-sdk/lib/event_listeners.js:456:46)
    at Request.callListeners (/Users/alvarogimeno/lab/node/aws/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/Users/alvarogimeno/lab/node/aws/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Users/alvarogimeno/lab/node/aws/node_modules/aws-sdk/lib/request.js:683:14)
    at ClientRequest.error (/Users/alvarogimeno/lab/node/aws/node_modules/aws-sdk/lib/event_listeners.js:295:22)
    at ClientRequest.<anonymous> (/Users/alvarogimeno/lab/node/aws/node_modules/aws-sdk/lib/http/node.js:89:19)
    at ClientRequest.emit (events.js:182:13)
    at ClientRequest.EventEmitter.emit (domain.js:442:20)
    at TLSSocket.socketErrorListener (_http_client.js:371:9)
    at TLSSocket.emit (events.js:182:13)
  message: 'Inaccessible host: `ec2.undefined.amazonaws.com\'. This service may not be available in the `eu-west-2\' region.',
  code: 'UnknownEndpoint',
  region: 'eu-west-2',
  hostname: 'ec2.undefined.amazonaws.com',
  retryable: true,
  originalError:
   { Error: getaddrinfo ENOTFOUND ec2.undefined.amazonaws.com ec2.undefined.amazonaws.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:50:26)
     message: 'getaddrinfo ENOTFOUND ec2.undefined.amazonaws.com ec2.undefined.amazonaws.com:443',
     errno: 'ENOTFOUND',
     code: 'NetworkingError',
     syscall: 'getaddrinfo',
     hostname: 'ec2.undefined.amazonaws.com',
     host: 'ec2.undefined.amazonaws.com',
     port: 443,
     region: 'eu-west-2',
     retryable: true,
     time: 2018-05-16T18:16:08.048Z },
  time: 2018-05-16T18:16:08.048Z }

Steps to reproduce the issue:

  const ec2 = new AWS.EC2({ apiVersion: '2016-11-15' })

  const instanceParams = {
    ImageId: 'ami-10fd7020',
    InstanceType: 't2.micro',
    MinCount: 1,
    MaxCount: 1
  }

  ec2.config.update({ region: 'eu-west-2' })

  const data = ec2.runInstances(instanceParams)

  data.promise().catch(console.log).then(console.log)

guidance

Most helpful comment

@AlvaroBernalG
The endpoint the service client uses is resolved when you instantiate the client. Since you're updating the region after instantiation, the endpoint isn't resolved correctly.

If you add the region to the object you pass to the constructor, you should get the correct endpoint:

const ec2 = new AWS.EC2({ apiVersion: '2016-11-15', region: 'eu-west-2'})

All 5 comments

@AlvaroBernalG
The endpoint the service client uses is resolved when you instantiate the client. Since you're updating the region after instantiation, the endpoint isn't resolved correctly.

If you add the region to the object you pass to the constructor, you should get the correct endpoint:

const ec2 = new AWS.EC2({ apiVersion: '2016-11-15', region: 'eu-west-2'})

Thanks @chrisradek. It's been a long day, my apologies for wasting your time.

@AlvaroBernalG
I'm sure this will help someone in the future too. Glad it's working now!

region solved it!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings