Search code examples
amazon-ec2amazon-elb

Can a single ELB serve multiple domains? Can it serve multiple subdomains?


I am wondering if ELB can route http requests to different ASGs (or different instances if the backend is a single instance based rather than ASG based), based upon the domain name.

  • Say, I am company owning two domains and these two domains serve different services. Can I put a single ELB in front of the two different logic serving ASGs? (See the following diagram for what is in my mind) enter image description here

  • (If the answer to the above question is 'NO', would you please explain why which may answer the next question all together?) And then I have a similar question, can ELB serve different subdomains from different ASGs (see the next diagram)?

enter image description here


Solution

  • No. An ELB evenly distributes traffic across the instances associated with it. Multiple AutoScaling groups can indeed be associated with a single ELB, however it isn't possible to influence the load balancing algorithm depending on any factor.

    In your case, you need 2 ELBs.

    A possible work around: If all your instances behind the ELB had Apache with Virtual Hosts running on them, you could serve different domains or subdomains using a single ELB. However, each of your instances would be identical - you wouldn't have some instances for domain 1 and some for domain 2.

    The moral of the story is that when using ELBs, all of your instances behind the ELB need to be stateless and do the same thing. And, you cannot influence how the ELB distributes traffic to the nodes behind it.

    A reading of the documentation would be of benefit to you.