简体   繁体   中英

Multiple API Gateways from different regions with the same Custom Name and different base path

I have 10 different APIs across two AWS regions (us-east-1, ca-central-1). Using base path mapping, us-east-1.example.com is serving 5 APIs in US and ca-central-1.example.com is serving the other 5 APIs (API Gateway). Although the backend is running the same code, it was part of the requirement from clients. Our clients are public universities and they want to have their own servers in their own country. For example, the current setup is using Custom Name & base path from API Gateway.

American universities:

us-east-1.example.com/harvard
us-east-1.example.com/stanford
us-east-1.example.com/mit

Canadian universities:

ca-central-1.example.com/ubc
ca-central-1.example.com/bcit
ca-central-1.example.com/waterloo

Is there a way to combine them into a single custom domain using Route 53 like the following?

api.example.com/harvard
api.example.com/ubc

I just talked to an AWS Professional and was told this is not a possible architecture.

You can definitely use CloudFront for this and you can use Route53 to make it available under your custom domain. Add each university as an origin and add a cache behavior for each of them with the path pattern of the university's name and the target the corresponding origin.

You'll have origins:

  • harvard => us-east-1.example.com
  • stanford => us-east-1.example.com
  • ubc => ca-central-1.example.com
  • ...

and cache behaviors:

  • /harvard => harvard (origin)
  • /stanford => stanford
  • /ubc => ubc

When a request comes in, CloudFront checks the path pattern and routes the response to the correct API Gateway endpoint. The downside is that you need to modify the CloudFront distribution when there is a new university you want to route to. I've written some articles about how routing in CloudFront works.

To host it under your own domain name, you need to use ACM to request a certificate for that domain, then add an Alternate Domain Name to the CloudFront distribution, and finally add an A (and AAAA) record to the Route53 hosted zone pointing to the distribution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM