DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Link  your sub-domain to AWS API Gateway
Paul Allies
Paul Allies

Posted on • Updated on

Link your sub-domain to AWS API Gateway

Let's hook up the name myapp.nanosoft.co.za to an AWS API Gateway

Create Certificate for Domain

  • Go to the Certificate Manager console
  • Request a certificate
  • Select "Request a public certificate"
  • Add one or more domain names, in my case I add myapp.nanosoft.co.za
  • Choose DNS validation
  • You'll be given a CNAME entry to which you'll need to register at your DNS Registrar e.g:
HOST: _xxxxxxxxxxxxxxxxxxxxx.myapp.nanosoft.co.za 
TYPE: CNAME
VALUE: _xxxxxxxxxxxxxxxx.xxxxxxxxx.acm-validations.aws.
Enter fullscreen mode Exit fullscreen mode

This is necessary to validate that you own the subdomain

  • Test the DNS Validation registration with
$> dig +short _xxxxxxxxxxxxxxxxxxxxx.myapp.nanosoft.co.za
Enter fullscreen mode Exit fullscreen mode

you should get a response of

_xxxxxxxxxxxxxxxx.xxxxxxxxx.acm-validations.aws.
Enter fullscreen mode Exit fullscreen mode
  • Once AWS has found this validation token, you'll notice that the certificate manager will update the status of the certificate from "Pending" to "Issued". Next, let's create an API Custom Domain record

Create a custom Domain

  • Go to the API Gateway console
  • Go to Custom domain names and create a domain name
    1. Choose TLS 1.2
    2. Regional Endpoint
    3. Choose the newly created Certificate for myapp.nanosoft.co.za
    4. Click "Create Domain Name"

Link the Domain Name to Rest API

  • Go to the API Gateway console
  • Go to Custom domain names
  • Select myapp.nanosoft.co.za
  • Configure the API mapping by choosing an API and Stage, Path is optional
  • Save mapping

Link the Domain Name to Rest API

  • Go to the Route 53 console
  • Create a Hosted Zone, In my case it would be nanosoft.co.za
  • Create an A Record for a subdomain by choosing Simple Routing
  • add the subdomain myapp to the existing nanosoft.co.za domain
  • Choose "A record"
  • For Value/Route to, choose "Alias to API Gateway API"
  • Choose the region where the api exists, in my case af-south-1
  • Choose the matching API gateway, e.g. d-xxxxxx.execute-api.af-south-1.amazonaws.com
  • Click "Define simple record"
  • Now that you have this A Record, we need a CNAME in our DNS to link the subdomain. Do so by adding a CNAME record at your DNS Registrar
Host: myapp, //or myapp.nanosoft.co.za depending on your DNS Registrar 
Type: CNAME, 
Value: d-xxxxxx.execute-api.af-south-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: