Exploring AWS ALB Path-Based Routing for Improved Traffic Management
When it comes to your HTTP and HTTPS-based application infrastructure, the load balancer is one of the significant components.
The Application Load Balancer, launched in 2016, supports content-based routing, works well for serverless and container-based applications, and is highly scalable.
Pre-Requisites:
VPC
IGW
Subnets
Route Table
Target groups
Load Balancer
Ec2 servers
Plan details:
Based on the Architecture below,
ALB: 10.10.0.0/16
ELB-PUB-A: 10.10.0.0/24
ELB-PUB-B: 10.10.1.0/24
IGW: 0.0.0.0/0
EC2-PUB-A: 10.10.11.0/24
EC2-PUB-B: 10.10.12.0/24
#!/bin/bash
yum install httpd -y
service httpd start
chkconfig httpd on
mkdir /var/www/html/app1
echo "<h1> Hi Guys..! Welcome to app1 Server</h1>" > /var/www/html/app1/index.html
echo "configured successfully"
#!/bin/bash
yum install httpd -y
service httpd start
chkconfig httpd on
mkdir /var/www/html/app2
echo "<h1> welcome to Cloud World! app2 is working.! </h1>" > /var/www/html/app2/index.html
echo "configured successfully"
Steps:
Create a VPC, 2 public subnets for the ELB, and 2 public subnets for EC2.
VPC created with name of ALB.
Internet Gateway is attached to VPC
4 subnets were created.
2 Route table added for 4 Subnets.
App1 & App2 โ Ec2 servers created. attached with user data.
Create 2 Target Group for 2 servers
Here is the place to attach your file path
Add app1 server to the Target group
Repeat the steps above: create a target group for app2 and attach the app2 server.
Create an Application Load Balancer
Attach your TG with LB
TG added a listener rule to forward traffic.
Apply path-based routing here.
Add both target groups and set up path-based traffic forwarding. Once everything is ready, copy the Load Balancer URL and paste it into your browser.
Outputs:
<URL>/app1
<URL>/app2
I hope the blog is useful! ๐ See you soon!! ๐
Follow me for more such Cloud โ๏ธ & DevOps-related articles. ๐
Subscribe to my newsletter
Read articles from Mr DevSecOps directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mr DevSecOps
Mr DevSecOps
Crowd to Cloud