Search code examples
amazon-web-servicesaws-api-gatewayamazon-route53

Understanding the health check and multi region implementation of API Gateway


I'm trying to implement a health check for multiple API Gateways deployed to multiple regions. For this, I'm following this article.

Long story short, you need to replicate the exact same API Gateways (and their corresponding Lambda functions) in all of the regions. The use Route53 to create one domain name backed by multiple endpoints.

My question is related to the way Route53's set up. In that article, health check endpoints are populated by API Gateway's Stage Invoke URLs. While region endpoints are populated by Target Domain Name from API Gateway's Custom Domain Name.

Why are these two endpoints populated by different values? If we can use Stage Invoke URL in the health check, why do we need to have Custom Domain Name in the first place? Why can't we just use the same Stage Invoke URL to populate the region endpoints?


Solution

  • If we can use Stage Invoke URL in the health check, why do we need to have Custom Domain Name in the first place?

    The stage URL is unique to each region. If you health-checked the custom domain, you'd be implicitly checking the region that was (a) closest to the individual health-checker and (b) already believed to be healthy, which would be useless as a health check target.

    On the other hand, if you don't create a custom domain that's the same in each region, then you wouldn't have a common domain name for your clients to access. You can't just point an arbitrary hostname at an API Gateway endpoint and have it work -- API Gateway needs to expect traffic for that hostname, which is what you're doing when you deploy with a custom domain.

    A related question might be why do you need the target domain name? Why not use it for the health checks? The target domain name is, as its name implies, only a target domain name, used only by DNS for routing. It shouldn't accept requests sent directly to it that don't use the custom domain for SSL and in the HTTP Host header.