I have a lambda function in all AWS regions. I have clients throughout the globe who will make a POST call to my base domain example.com
. It is the responsibility of my (kind-of) load-balancer to make sure that the requests are routed to the API gateway of the region which is closest to the client, in order to minimize the latency.
So, far I have the following configuration:
- Lambda functions deployed on each region
- Custom domain names for each of the API gateways, which exposes a CloudFront domain name. For instance, N.California region has custom domain name
us-west-1.example.com
configured and a mapping of the path which calls my lambda. The CloudFront URL for this API gateway isd12345123.cloudfront.net
- A RecordSet of type
A
in the Route53 hosted zone forus-west-1.example.com
which is an alias ofd12345123.cloufront.net
. If I make a POST call tous-west-1.example.com/1.0/localdb
, it returns me the correct output. - A traffic policy in Route53 and a policy record, for
default.example.com
ofA
type, which has a geo-proximity rule assigned to it, which redirects the traffic to the CloudFront instance (the same instance which is exposed after adding the custom domain name in that region) of the region. This creates an entry fordefault.example.com
in the hosted zone of typeA
- A RecordSet of type
A
in the Route53 hosted zone forexample.com
which is an alias todefault.example.com
, so that the traffic which comes toexample.com
can be routed todefault.example.com
After these configurations, when I make a call to example.com
, I receive a 403
response from Cloudfront, calling it a Bad Request
Thanks
default.example.com
won't do what you expect, so answering what you've asked won't help. Invoking Lambda functions typically means using API Gateway, and it is not sufficient to point different CNAME records to different API Gateway deployments in different regions -- for a given hostname, you can only configure API Gateway to expect that hostname in one region. Please provide more details about what you are actually trying to accomplish and your specific configuration. - Michael - sqlbotHost
header to the hostname in the URL in the address bar. Regardless of any intermediate DNS resolution steps, the original hostname is what the destination sees. That is the fundamental problem you are up against. There is not currently an AWS native, managed, serverless solution for this. It requires regional proxy servers to rewrite those host headers, or redirects to the regional hostnames, or... if your APIs always require < 3 seconds to process requests, then there's a potential solution in Lambda@Edge. - Michael - sqlbot