ALB Path-based Routing in AWS
When it comes to your HTTP and HTTPS-based application infrastructure, the load balancer is one of the significant components.
Application Load Balancer, launched in 2016, supports content-based routing, works well for serverless & 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 VPC, 2 Public Subnets for 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
Do the same steps as above; again, 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 TG and forward path-based traffic to your path. "Once all the requirements are in place.
Copy the Load Balancer Url and paste in the browser.
Outputs:
<URL>/app1
<URL>/app2
I hope the blog is useful! 🌟 See you soon!! 👋
Follow me for more such Cloud ☁️ & DevOps-related articles. 🚀