Day 41: Setting up Application Load Balancer with AWS EC2

Day 41: Setting up Application Load Balancer with AWS EC2


4 min read

Hi, I hope you had a great day yesterday learning about the launch template and instances in EC2. Today, we are going to dive into one of the most important concepts in EC2: Load Balancing.

What is Load Balancing?

Load balancing is the distribution of workloads across multiple servers to ensure consistent and optimal resource utilization. It is an essential aspect of any large-scale and scalable computing system, as it helps you to improve the reliability and performance of your applications.

Elastic Load Balancing

Elastic Load Balancers (ELB) are a fundamental component of Amazon Web Services (AWS) that distribute incoming application or network traffic across multiple Amazon EC2 instances to ensure high availability and reliability. There are several types of ELBs in AWS, each designed to address specific use cases. Here are the three types of Elastic Load Balancing:

  1. Application Load Balancer (ALB): It is a Layer 7 (Application Layer) Load Balancer. It is best suited for routing HTTP/HTTPS traffic and provides advanced traffic management, content-based routing, and support for containerized applications. It provides the facility of Content-based routing, path-based routing, host-based routing, support for WebSocket and HTTP/2, and integration with AWS WAF for security.

  2. Network Load Balancer (NLB): It is a Layer 4 (Transport Layer) Load Balancer. It is designed for handling TCP/UDP traffic, and it's ideal for ultra-high performance, low-latency, and high-throughput applications. It provides the facility of supporting TCP and UDP-based protocols, supports static IP addresses, and can route traffic to instances in private subnets.

  3. Classic Load Balancer (NLB): It is a combination of both layer 4 and layer 7 Load Balancer. The original Elastic Load Balancer is suitable for simple applications but is less feature-rich compared to ALB and NLB. It provides the feature of Basic request routing, stickiness, and support for both HTTP/HTTPS and TCP/UDP protocols.

Task 1

launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.

Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name also do it for 2nd instance which includes " This is First today's Task ".

Copy the public IP address of your EC2 instances.

Open a web browser and paste the public IP address into the address bar.

You should see a webpage displaying information about your PHP installation.

Step 1: Launch Two EC2 Instances with Ubuntu AMI:

  • Log in to your AWS Management Console. Navigate to the EC2 service.

  • Click on the "Launch Instance" button. Choose an Ubuntu AMI as your base image.

  • Select an instance type (e.g., t2.micro).

  • In the "Configure Instance Details" section, provide user data. Use a script to install Apache and modify the index.html file. The user data might look like this:

      apt-get update
      apt-get install -y apache2
      echo 'Your Name' > /var/www/html/index.html
  • Replace your actual name here.

  • Access the ec2 instance by copying and pasting the public IP address of the ec2 instance.

Step 2: Access the Apache Web Server:

  • Open any web browser. Paste the public IP address of the first ec2 instance. Your name should be displayed on the webpage.

  • Paste the IP address of your second ec2 Instance. The webpage displayed the " This is First today's Task "


Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.

Add EC2 instances which you launch in task-1 to the ALB as target groups.

Verify that the ALB is working properly by checking the health status of the target instances and testing the load-balancing capabilities.

Step 1: Create an Application Load Balancer (ALB):

  • Log in to your AWS Management Console. Navigate to the EC2 service.

  • In the navigation pane, under "Load Balancing," choose "Load Balancers."

  • Click the "Create Load Balancer" button. Select "Application Load Balancer" as the load balancer type.

  • Configure the basic settings, such as the name, VPC, and availability zones.

  • Configure the security settings as required.

  • Configure the routing and create a new target group.

  • Configure health checks and other settings according to your needs.

  • Review your settings and create the ALB.

Step 2: Add EC2 Instances to the Target Group:

  • After creating the ALB, select the target group created in the previous step. In the "Targets" tab, click "Edit" to add target instances.

  • You can add the EC2 instances you launched in Task 1 by specifying their instance IDs or choosing them from the list of registered instances.

  • Review and save the changes.

Step 3: Verify ALB Functionality:

  • In the ALB management console, navigate to the "Listeners" tab and confirm that the listener routes traffic to the target group.

  • In the "Target Groups" section, select the target group and check the health status of the registered instances. They should be marked as "healthy."

  • Test the ALB by accessing the ALB's DNS name or public IP address in your web browser. The ALB should distribute traffic to your target instances.

Follow these steps to complete the task.

<That's all for today. Hope you like it. FOLLOW to join me in the journey of DevOps>