Skip to content

How can we achieve path-based routing for AWS Amplify using an NGINX proxy?

0

I deployed three microservices on AWS Amplify, each accessible via its own URL (e.g., https://app1.amplifyapp.com, https://app2.amplifyapp.com, and https://app3.amplifyapp.com). I want to consolidate these microservices under a single DNS, such as https://mydomain.com, and route them based on the path: https://mydomain.com/app1 → Amplify App 1 https://mydomain.com/app2 → Amplify App 2 https://mydomain.com/app3 → Amplify App 3

2 Answers
0

While AWS Amplify doesn't natively support path-based routing for multiple applications under a single domain, you can achieve this setup using an NGINX proxy in combination with Amazon API Gateway or Amazon CloudFront.

Here's a high-level approach to implement path-based routing for your Amplify apps:

  1. Set up an NGINX server as a reverse proxy. This can be done on an EC2 instance or using a container service like ECS or EKS.

  2. Configure NGINX to route requests based on the path. Your NGINX configuration would look something like this:

server {
    listen 80;
    server_name mydomain.com;

    location /app1 {
        proxy_pass https://app1.amplifyapp.com;
    }

    location /app2 {
        proxy_pass https://app2.amplifyapp.com;
    }

    location /app3 {
        proxy_pass https://app3.amplifyapp.com;
    }
}
  1. Use Amazon API Gateway or Amazon CloudFront as the entry point for your domain (mydomain.com). This will handle SSL termination and provide additional features like caching and security.

  2. Configure API Gateway or CloudFront to forward requests to your NGINX server.

  3. Set up your DNS (Route 53 or another DNS provider) to point mydomain.com to the API Gateway or CloudFront distribution.

This approach allows you to maintain the benefits of Amplify for each individual app while providing a unified entry point for your users. It's important to note that this setup introduces additional complexity and potential points of failure, so you'll need to ensure proper monitoring and management of the NGINX server.

Alternatively, if you're open to restructuring your application, you could consider consolidating your microservices into a single Amplify app with different routes. This would allow you to use Amplify's built-in routing capabilities and avoid the need for an external proxy.

Remember to carefully consider factors like scalability, maintenance, and cost when implementing this solution. You may also want to explore other AWS services like Application Load Balancer or AppSync if they better suit your specific use case.
Sources
Path routing pattern - AWS Prescriptive Guidance

answered 2 years ago

  • can u explain in details bcz cloudfront not able to access amplify url it show 403 error

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.