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.

已提问 2 年前554 查看次数
1 回答
1
已接受的回答

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
专家
kentrad
已回答 2 年前
  • 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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则