0

I am deploying a API gateway to AWS which gives me a random URL and I'd like to configure custom domain. Based on my understanding, I just need to create a CNAME in route53 for the custom domain point to the api gateway random URL but after some reading, it says I also need to create a custom domain in API gateway. I can make it work but I don't understand why I need that in API gateway. Isn't it just a CNAME which can make it work?

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • A `CNAME` is not enough if you want to omit the stage from the URL. – luk2302 Jun 02 '21 at 09:48
  • why CNAME is not enough? Is it just because the stage in url `***/$stage` at the end? If yes, can I add the path in route53 CNAME? – Joey Yi Zhao Jun 02 '21 at 10:38
  • 1
    No, a CNAME cannot point to a path: https://stackoverflow.com/questions/9444055/using-dns-to-redirect-to-another-url-with-a-path – luk2302 Jun 02 '21 at 11:33

1 Answers1

0

Behind the scene, API Gateway does 2 things automatically for you when you create a custom domain name, e.g: example.com via its interface

  1. It creates a hidden cloudfront distribution with the domain: xyz.cloudfront.net

  2. It configures that distribution to allow CNAME from your example.com

What you will have to do manually is to create an alias record in Route53 pointing to xyz.cloudfront.net.

As you notice, you can do all these steps manually through Cloudfront and Route 53 interfaces and it would still work. However, since API Gateway is not aware of this manual configuration, you have to do the mapping (between cloudfront and API Gateway) yourself, instead of point-and-click interface provided by API Gateway interface.

In other words, API Gateway simplifies several Cloudfront configuration steps you have to do otherwise.

duyvh
  • 419
  • 3
  • 5