Bootstrap FreeKB - Amazon Web Services (AWS) - Application Load Balancer (ALB) HTTP Host Header Listener Rules
Amazon Web Services (AWS) - Application Load Balancer (ALB) HTTP Host Header Listener Rules


If you are not familiar with AWS Application Load Balancers, check out my article FreeKB - Amazon Web Services (AWS) - Getting Started with Application Load Balancer (ALB).

Let's say you have an Application Load Balancer configured to listen on HTTP port 80 and let's say app "a" on each EC2 instance is listening on port 12345 and app "b" in each EC2 instance is listening on port 67890. So how do we load balance between the apps? This is where HTTP Host Header Listener Rule comes into play.

 

Let's create two Target Groups, one for app "a" and the other for app "b".

aws elbv2 create-target-group --name a-target-group --protocol HTTP --port 80 --target-type instance --vpc-id vpc-123abd654dsf356s1

aws elbv2 create-target-group --name b-target-group --protocol HTTP --port 80 --target-type instance --vpc-id vpc-123abd654dsf356s1

 

And register both EC2 instances in a-target-group with port 12345 and register both EC2 instance in b-target-group with port 67890.

aws elbv2 register-targets \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/a-target-group/af5707bbd67c69ab \
--targets Id=i-a0908ab089f9008ab,Port=67890 Id=i-c099080ab09dc0909,Port=12345

aws elbv2 register-targets \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/b-target-group/af5707bbd67c69ab \
--targets Id=i-a0908ab089f9008ab,Port=67890 Id=i-c099080ab09dc0909,Port=67890

 

Now let's create 2 HTTP Host Header Listener Rule

  • if HTTP Host Header is a.freekb.link forward the request onto a-target-group
  • if HTTP Host Header is b.freekb.link forward the request onto b-target-group

 

And then create 2 A Alias records. In this example, both a.freekb.link and b.freekb.link forward reqeusts onto the Application Load Balancer.

 

Now when I go to a.freekb.link, the request is routed onto the Application Load Balancer, and then the HTTP Host Header Listener Rules are evaluated, and the Rule containing a.freekb.link is matched and the request get forwarded onto a-target-group, returning app "a".

 

Likewise, when I go to b.freekb.link, the request is routed onto the Application Load Balancer, and then the HTTP Host Header Listener Rules are evaluated, and the Rule containing b.freekb.link is matched and the request get forwarded onto b-target-group, returning app "b". How cool!

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 170e0a in the box below so that we can be sure you are a human.