- Newest
- Most votes
- Most comments
Based on your situation, the most suitable and industry-standard approach would be to use CloudFront to serve both your frontend and backend applications under the same domain (example.com). This solution offers several advantages:
-
Unified Domain: You can use example.com for both frontend and backend, achieving your goal of using the same root domain.
-
Performance: CloudFront's global edge network can significantly improve the performance of both your frontend and backend applications by caching content closer to users.
-
Security: CloudFront provides additional security features like AWS Shield for DDoS protection.
-
Flexibility: You can configure different behaviors in CloudFront for different path patterns, allowing you to route requests appropriately.
Here's how you can implement this:
-
Set up your CloudFront distribution with your frontend S3 bucket as the default origin.
-
Add a new origin in the same CloudFront distribution pointing to your Kubernetes Gateway.
-
Create a new behavior in CloudFront for backend requests (e.g., /backendapp/*) and set the origin to your Kubernetes Gateway.
-
Ensure that the "Host" header is forwarded to the origin in the CloudFront behavior for backend requests. This is crucial for the SNI (Server Name Indication) to work correctly with your ALB.
-
Update your DNS records to point example.com to your CloudFront distribution.
Regarding your concern about latency: While it's true that requests to the backend will go through CloudFront first, the added latency is typically minimal and is often outweighed by the benefits of CloudFront's global edge network. CloudFront can also cache certain backend responses, potentially improving performance for subsequent requests.
This approach allows you to maintain control over routing through your Kubernetes Gateway while benefiting from CloudFront's global network and features. It also solves the issue of people accessing CloudFront directly through its domain, as you can standardize on your custom domain.
Remember to properly configure security groups, NACLs, and other network settings to ensure that your backend services only accept traffic from CloudFront and not directly from the internet.
Sources
cloudfront distribution with several origins | AWS re:Post
Cloud Front To ALB SNI | AWS re:Post
Use custom URLs by adding alternate domain names (CNAMEs) - Amazon CloudFront
