We are deploying an application using AWS elastic beanstalk with autoscaling, behind a load balancer. Currently we are using an application load balancer.
We would like to be able to route some users/requests to a specific instance behind the load balancer, ideally by URL. For instance, if a http reqest were to come in for URL http://our_app_domain/something/123, it should be routed to instance 123, whereas http://our_app_domain/something/456 should be routed to instance 456. A POST or other http header could also work though, if that were easier. Or it could even involve something being done on the client side using Javascript.
What is important to us is that this could be any instance, out of many autoscaled ones. The flow we have in mind is that a user goes to an instance, that instance gives them a link somewhere, and then if someone else visits that link they'll end up on the same instance.
Is something like this possible?
I've found some suggestions to find the instance ID of a specific instance here: How to find ec2 instance that is processing my request that is forwarded by an Elastic Load Balancer
And this also mentions the cookie that ELB uses to maintain session stickiness - could there be a way to overwrite the cookie to make ELB route to a different instance?
Another thing I've found is target groups. We could create many target groups with one instance in them each, and then what we want to do should work, I believe. But the problem is that we want this to work with autoscaling, and I don't think there's a way to autoscale target groups (only instances within target groups), is that right?
One alternative could be that the instances themselves tell the load balancer if they want to accept the connection, but I don't know if that could work. E.g. if instance 456, on receiving a request with a URL for instance 123, returns some temporary HTTP error code, and then the autoscaler reroutes it to another instance, until it eventually routes it to 123?
Any other way of doing this would be fine as well of course! Thanks so much!