'Cloudfront with latency based domain as origin finds wrong region

I have a limitation whereby I must run both HTTP and WS through a single TLD, and unfortunately it appears that API gateway requires a separate domain for each protocol as they're separate APIs (correct me if I'm wrong, as that would probably solve the issue).

The way that I've currently implemented it is as follows

messages.foo.com -> cloudfront dist -> origin messages-http.foo.com
messages.foo.com/ws -> cloudfront dist -> behaviour w/ origin messages-ws.foo.com

Both messages-http.foo.com and messages-ws.foo.com are deployed in many regions. The two main ones I'll focus on are af-south-1 and eu-central-1 where I noticed the issue.

If I visit messages-http.foo.com from a machine in af-south-1, latency based routing finds the api gateway/lambda in af-south-1, as expected.

However, if I visit messages.foo.com from the same machine in af-south-1, it finds the api gateway/lambda in eu-central-1.

The api gateways in each region are regional endpoints with custom domains in front, with latency based routing in route 53. There are no lambda@edge functions in use, nor cloudfront functions.

Having read this page about the Cloudfront cache locations in EMEA, it seems to suggest that there are edge locations, but no edge caches in Africa and I wondered if this could be the cause of my issue? By the time the request hits Cloudfront, the closest origin latency wise is now Europe, not Africa?

I'm looking for either alternate solutions to 1 domain->2 api gateways (http & ws), or how to route my traffic properly from Cloudfront to latency based routed domains.

Any suggestions would be much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source