Home > database >  Route53 traffic routing based on user location with api gateway
Route53 traffic routing based on user location with api gateway

Time:01-02

I have an application that is in the us-east-1 region with following

API gateway -> lambda -> dynamo DB

I wanted to have these resources in multiple regions (in `Mumbai and Europe) to decrease the latency.

What I did

  • I have created Global tables for my data in dynamoDb
  • Created 3 separate lambda functions in 3 regions
  • Created 3 API gateway rest APIs in 3 regions

Now the question is

  • How do I have just one subdomain (api.example.com) which can route the request to the appropriate API gateway endpoint based on user location that will definitely reduce the latency.

I created a custom domain in my API gateway like us-east-1-api.example.com, ap-south-1-api.example.com, eu-central-1-api.example.com and mapped my APIs.

Now in the Route53, I created an A record for api.example.com but I am not getting any API gateway resources to connect to. but when I try to have the same subdomain in route53 such as us-east-1-api.example.com then it shows me the us-east-1 API gateway CloudFront resource.

but this would mean that I will have to create 3 different subdomains records which is not what I wanted.

I want to have a single subdomain that can route the traffic to the appropriate API gateway based on the user location.

I tried searching a lot but did not find what I was looking for. would appreciate any help.

CodePudding user response:

Normally you would create api.example.com as latency records.

In your case you would have three latency recordcs called api.example.com. Each of them would point to other A alias record in your HZ (us-east-1-api.example.com, ap-south-1-api.example.com, eu-central-1-api.example.com):

                             |-> us-east-1-api.example.com (ALIAS to API gateway in that region)
api.example.com (latency) -> |-> ap-south-1-api.example.com (ALIAS to API gateway in that region)
                             |-> eu-central-1-api.example.com (ALIAS to API gateway in that region)
  • Related