An Application Load Balancer (ALB) is one of the types of load balancers provided by Amazon Web Services (AWS) within the Elastic Load Balancing (ELB) service. ALB is designed to handle and distribute incoming application traffic across multiple targets, such as EC2 instances, containers, and IP addresses, based on specified rules.
Aim
To configure an Application Load Balancer (ALB) in Amazon Web Services (AWS) that distributes traffic to EC2 instances across two subnets in different AZ within the default Virtual Private Cloud (VPC). Additionally, configure the EC2 instances with an HTTP web server.
Objective
- Launch two EC2 instances, each in a different subnet within the the default VPC.
- Set up an Application Load Balancer (ALB) to distribute incoming traffic across the EC2 instances.
- Configure the EC2 instances as Linux servers with an HTTP web server.
- Ensure the setup allows for high availability and fault tolerance by leveraging multiple Availability Zones.
Steps
Step 1: Launch two EC2 Instances
- Go to the EC2 Dashboard in the AWS Management Console.
- Click "Launch Instance."
- Select an Amazon Machine Image (AMI) (e.g., Amazon Linux 2).
- Choose an instance type.
- Under "Network," select the default VPC.
- Choose a subnet in an Availability Zone (e.g., us-east-1a).
- Under "Advanced Details > USER DATA SCRIPT:
#!/bin/bash
yum update -y
yum upgrade -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "<h1>Instance A is running</h1>" > /var/www/html/index.html
- Second Ec2 Instance
#!/bin/bash
yum update -y
yum upgrade -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "<h1>Instance B is running</h1>" > /var/www/html/index.html
- Configure the security group to allow HTTP (port 80) and SSH (port 22) traffic.
- Launch the instance.
Step 2: Create an Application Load Balancer
1. Create ALB:
- Go to the EC2 Dashboard.
- Under "Load Balancing," click "Load Balancers."
- Click "Create Load Balancer" and choose "Application Load Balancer."
2. Configure Security Groups:
- Create or select an existing security group that allows inbound HTTP/HTTPS traffic.
3. Configure Routing:
- Create a target group.
- Choose "Instances" as the target type.
- Configure the health checks for the target group.
- Register your EC2 instances with this target group.
4. Review and Create:
- Review your configuration and create the load balancer.
Step 4: Test the Setup
Test ALB:
- Note the DNS name of the ALB.
- Access it via a web browser to ensure it distributes traffic to your EC2
Conclusion
By completing these steps, you have successfully configured an Application Load Balancer (ALB) in AWS within the default VPC and subnets. The ALB now efficiently distributes incoming traffic across EC2 instances in multiple Availability Zones, ensuring high availability and fault tolerance
Top comments (0)