Is there a way to pass unique data about different load balancers into a custom header?

0

Current situation: we have 2 load balancers because we have 2 separate ECS stacks, one is the current stack and one is the CDK stack which we are moving to but for now we need to test that both can work in tandem. The routing will be split 50/50 but we need to know when our customer clicks on the website and the different web pages in our website, which load balancer they are on / which stack have they been routed to. This is so that if an error occurs we can debug better and we will also know if the CDK stack is getting any errors.

Our app is created with next.js and react. I have created a custom header in the next.config.js file. Now I just need to figure out how to pass a unique identifier such as the load balancer name into this header.

Does anyone have any suggestions? Ultimately the end goal is to know when someone clicks on a page on our website which stack they were routed to (CDK or non CDK stack) so other options/ways to achieve what we want are welcome.

If it helps we have the infrastructure code in the repo in the infra folder which sits outside / on level with the src folder. And in this we have the ecs.ts file where we have the variable: loadBalancerName: app-${environment},

thanks!

2 Answers
1

This blue-green deployment would be easier to do with a single ALB if that is possible.

https://aws.amazon.com/blogs/aws/new-application-load-balancer-simplifies-deployment-with-weighted-target-groups/

See Target Group Stickiness

There are situations when you want the clients to experience the same version of the application for a specified duration. Or you want clients currently using the app to not switch to the newly deployed (green) version during their session. For these use cases, we also introduce target group stickiness. When target group stickiness is enabled, the requests from a client are all sent to the same target group for the specified time duration. At the expiry of the duration, the requests are distributed to a target group according to the weight. ALB issues a cookie to maintain target group stickiness.

Alternatively, you could use Route53 routing policy to split your traffic to different load balancers and base the decission on things like geo locatation or client IP (or anything else than weighted) that is not going to change between requests. This wouldn't get you 50/50 distribution thought.

https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html

profile picture
EXPERT
Kallu
answered 5 months ago
0

If you enable ALB logging you can search Athena after the case to see who’s hitting what.

If you looking for real time information so your app knows another option could be to have 2 different WAF Acls. One tied to each ALB. Set a custom header as the request passes through the WAF to the alb so your application can detect its route.

https://docs.aws.amazon.com/waf/latest/developerguide/customizing-the-incoming-request.html

profile picture
EXPERT
answered 5 months ago

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