API Gateway Custom Domain Name getaddrinfo ENOTFOUND

Viewed 2088

I have created an api using AWS API Gateway and would like to attach a custom domain name to it. I followed this tutorial and have done the following:

  1. Created new certificate on Certificate Manager (mydomain.io and *.mydomain.io)
  2. Added CNAME to GoDaddy (since mine was purchased from Godaddy)
  3. Set up a api-dev.mydomain.io on API gateway > Custom domain names, and mapped it to the API and dev stage in the "API Mappings".
  4. On Route 53, added api-dev.mydomain.io as an A record and direct it to the API (the API domain name is correct) in step 3.

I believe that my setup should be correct to the best of my knowledge, and have waited 1 hour for it to "take effect".

I then write a simple script to test it but it throws the above error.

Code:

const axios = require("axios")

let baseUrl = "https://api-dev.mydomain.io"
let key = MY_API_KEY
let headers = {
    headers: {
        "x-api-key": key
    }
}

let usersEndpoint = baseUrl + '/token?email=someemail@gmail.com'

axios.get(usersEndpoint, headers)
.then(response => {
    let data = response.data
    console.log(data)
})
.catch(err => console.log(err))

Error message:

Error: getaddrinfo ENOTFOUND api-dev.mydomain.io
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'api-dev.mydomain.io',
  config: {
    url: 'https://api-dev.mydomain.io/token?email=someemail@gmail.com',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'x-api-key': MY_API_KEY,
      'User-Agent': 'axios/0.21.1'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    ...

What am I missing?

1 Answers

Based on the comments.

The issue was that api-dev.mydomain.io was created in Route 53, while it was managed by GoDaddy (name servers were not changed to Route 53).

The solution was to create api-dev.mydomain.io record in GoDaddy, rather then in Route 53.

Alternatively, to manage the domain in Route 53, one would have to updated name servers in GoDaddy to point to Route 53 Hosted Zone as explained in Update the NS record with your current DNS service provider to use Route 53 name servers.

Related