简体   繁体   中英

AWS - Path based routing to amplify apps

I have a two frontend apps served in two different amplify applications. I want to forward the request based on the path to different servers using an Application Load Balancer (I'm open to any other tool that you might suggest as well). For example:

在此处输入图像描述

But as far as I know, ALB path routing works with EC2 instances only. Is there a way to achieve this with two amplify instances?

I thought to create a EC2 instance with a tunnel to the amplify instance but I'm not sure if is the best solution.

The main goal of doing this is share the localstorage of these two applications in the same domain. So is important that the request is forwarded and not redirected to the amplify domains

Either ways, if you have in mind any other way to achieve this, I'm open to suggestions as well

That's true that ALB only supports instance, Ip or Lambda function only and no other AWS resources.

You can achieve your path based routing using CloudFront

  • Create a cloudfront which will front both the amplify apps
  • Add both the amplify app URL as 2 origins to the cloudfront.
  • Setup cache behavior path pattern settings for both the origins for example /srv1 path pattern should map to 1st amplify app and similarly for the /srv2 -> 2nd amplify app.
  • Note :- you will need a default behaviour too for this cloudfront (for example none of the request matches your path pattern the request will go to this default behaviour for example a custom error page;)
  • Note:- order of the path pattern is imp check reference links for more explanation

Links -> reference 1 , reference2 , https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern

My personal take on this:- amplify of course does help in development by taking away all the abstractions but at the same time you loose the control, instead if i were you i would have gone with ECS fargate with ALB combination which of course give me better control for future requirements and cost management.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM