title: Routing to API gateway using AWS Route 53
body: <p>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 <code>example.com</code>. 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.</p>
  
  <p>So, far I have the following configuration:</p>
  
  <ul>
  <li>Lambda functions deployed on each region </li>
  <li>Custom domain names for each of the API gateways, which exposes a CloudFront domain name. For instance, N.California region has custom domain name <code>us-west-1.example.com</code> configured and a mapping of the path which calls my lambda. The CloudFront URL for this API gateway is <code>d12345123.cloudfront.net</code> </li>
  <li>A RecordSet of type <code>A</code> in the Route53 hosted zone for <code>us-west-1.example.com</code> which is an alias of <code>d12345123.cloufront.net</code>. If I make a POST call to <code>us-west-1.example.com/1.0/localdb</code>, it returns me the correct output.</li>
  <li>A traffic policy in Route53 and a policy record, for <code>default.example.com</code> of <code>A</code> 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 for <code>default.example.com</code> in the hosted zone of type <code>A</code></li>
  <li>A RecordSet of type <code>A</code> in the Route53 hosted zone for <code>example.com</code> which is an alias to <code>default.example.com</code>, so that the traffic which comes to <code>example.com</code> can be routed to <code>default.example.com</code></li>
  </ul>
  
  <p>After these configurations, when I make a call to <code>example.com</code>, I receive a <code>403</code> response from Cloudfront, calling it a <code>Bad Request</code></p>
  
  <p>Thanks</p>