'Routing /api endpoints to EC2 instance

I am currently routing www.example.com to my CloudFront distribution to server the frontend.

How can I point the /api endpoint to the load balancer? I tried created a new hosted zone in the for example.com/api but my /api endpoints seem to still be hitting CloudFront.



Solution 1:[1]

Route53 is a DNS service. DNS only handles translating hostnames to IP addresses. DNS does not handle the path portion of a URL in any way. The /api part of the URL is never even sent to Route53.

It's entirely unclear what you mean when you say you created a new hosted zone for the /api path.

The solution to your problem is to configure your load balancer as a second origin in your CloudFront distribution, and configure CloudFront to route /api requests to that origin.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Mark B