In this post we will create an ALB Application Load Balancer
in AWS with target group of two ec2 instances(distributing incoming among two ec2 instances). Also we will see how mutiple requests will be shared among these instances while we will hit only load balancer url.
EC2 Instances
For this post I already have two ec2 instances and accessible with their respective Public IPv4 address over HTTP.
These instances produces below output -
But if you want to create a new instance then follow this article. While creating new instance pass this user data
under Advanced Details
option.
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from instance at IP : ----- $(hostname -f) ----- </h1>" > /var/www/html/index.html
Create Application Load Balancer
- Go to Load Balancers from EC2 Screen
2. Click on Create Load Balancer
3. Click create under Application Load Balancer
4. Provide Name
5. Scroll below and Select Network Mappings with 1 or 2 Avalability Zones.
Include all Avalability Zones in which EC2 instances exists.
6. Scroll below and click on create a new security group to allow only http traffic into ALB.
Create security group with below highlighted properties.
Move back to ALB creation window and select new created security group. If new created security group doesn’t appear then click on refresh (highlighted below in green)
7. Create target group of two EC2 instances we already have.
Provide target group name and target type as instances
Keep eveything else as it is and scroll below, click on next.
On next page, select instances that you want to include in your target group and click on include pending below and then create target group.
Now move back to create ALB window and select newly created target group.
Now scroll below and create load balancer. New ALB is created.
After few minutes ALB will be active and ready to use.
Test
Now if we hit ALB url multiple times then we will see different output based on instance serving that request.
Conclusion
In this post we created an Application Load Balancer in AWS over two instances and saw how mutiple requests shared among them.