Search code examples
amazon-web-servicesamazon-cloudfrontaws-api-gateway

What is the difference between a Custom Domain Name at the API Gateway and a CloudFront Instance with a Custom Domain?


I'm currently extensively using the API Gateway as a source for CloudFront. My CloudFront serves other things as well, such as plain files from S3.

I've recently been looking into improving the current setup, and noticed the "Custom Domain Names" option in API Gateway.

From what I've understood, using it creates an unconfigurable CloudFront instance. I've not been able to find much information beyond that.

Are there any advantages to using API Gateway's Custom Domain Names over using a self-managed CloudFront instance?


Solution

  • When you use AWS CloudFront you can configure different Origins such as S3, API Gateway & etc to the distribution which allows to serve different services through same domain. e.g you can serve mydomain.com points to index.html in S3 and mydomain.com/api/* points to API Gateway. This allows for the frontend JavaScripts to access the API without the need for Cross Origin Request support at API Gateway which avoids sending Options preflight(If you have headers like Cookie, Authorization & etc.) request by the browser.

    On the other hand you can configure Custom Domain Names to API Gateway. This allows to define a Custom Domain as well as a Custom SSL Certificate using AWS Certificate Manager. The main difference is, if you have a frontend application, you need to define two domains(or different subdomains) for the frontend served from S3 and API. When accessing the API from different domain it will require to have CORS configured at the API Gateway and can affect performance based on the latency.