Architecture for request forwarding to multiple applications within same domain

0

I have multiple websites hosted in different environments such as S3 static HTML, self-hosted WordPress on Amazon Lightsail, application on Elastic Beanstalk, and external sites (e.g. Wordpress.com/Wix/Webflow).

I want to unify all those applications under a single domain name, let's say www.example.com. The routing are using a request path and also a user-agent.

The scheme looks like below

image

If the request, for example, is https://www.example.com/a, it will be forwarded (not redirected) to Site A. If the request is https://www.example.com/d and accessed with mobile devices, it will be forwarded to Site B, but if accessed with desktop devices, it will be forwarded to Site C. When the request is https://www.example.com/sitemap.xml it will be forwarded to a public file stored in S3.

One solution that I have in my mind is using ALB with Routing. But ALB only allows 3 kinds of target groups, as far as I know: 1) instance, 2) IP, and 3) Lambda. So I am thinking of targeting Lambda which serves as a proxy to the applications. Something like below.

image2

I am wondering if there are better solutions.

asked 2 years ago531 views
1 Answer
1
Accepted Answer

You can do this with a CloudFront distribution with multiple origins and behaviors. You will use a NoCache policy so all requests are forwarded to your origins except maybe your S3 objects. You will need to use Lambda@Edge or CloudFront Functions to handle the user-agent requirement.

Take a look at Accelerate your content using Amazon CloudFront

profile pictureAWS
EXPERT
kentrad
answered 2 years ago
  • Hi @kentrad, thanks a lot for the comment. The solution looks great! But I am wondering, do you think my initial ALB solution could work? And also what are the trade-off between this one and the ALB solutions?

  • @Petrabarus. Your Solution has more moving parts that you need to take care of is the first point. An ALB involves more costs compared to CloudFront. Using Lambdas as a Proxy is one of the Lambda Anti Patterns. And you have to pay for the wait-time till your Response arrives in your Lambda Function.

    Hope this helps

  • @kentrad that makes sense totally! thanks a lot for the answer. really appreciate the customer obsessions.

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.

Guidelines for Answering Questions