Skip to main content

Command Palette

Search for a command to run...

AWS Day 36: Load Balancing EC2 Instances with Application Load Balancer (ALB) | KodeKloud 100 Days of Cloud

Updated
5 min readView as Markdown
AWS Day 36: Load Balancing EC2 Instances with Application Load Balancer (ALB) | KodeKloud 100 Days of Cloud
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

On Day 36 of the KodeKloud 100 Days of Cloud Challenge, I built a complete Application Load Balancer (ALB) architecture on AWS.

Instead of exposing an EC2 instance directly to the internet, an Application Load Balancer sits in front of it and intelligently distributes incoming HTTP requests. Although this lab uses a single EC2 instance, the same architecture easily scales to multiple instances for high availability and fault tolerance.

This exercise covered creating a custom security group, launching an Ubuntu EC2 instance with User Data, installing Nginx automatically, configuring an Application Load Balancer, creating a Target Group, and validating traffic flow through the ALB DNS.

Lab Objective

The goal of this lab was to:

  • Create a Security Group named devops-sg

  • Allow HTTP traffic from the ALB

  • Launch an Ubuntu EC2 instance named devops-ec2

  • Install Nginx automatically using User Data

  • Create an Application Load Balancer named devops-alb

  • Create a Target Group named devops-tg

  • Register the EC2 instance as a target

  • Route HTTP traffic from the ALB to the EC2 instance

  • Verify the Nginx page using the ALB DNS

Architecture Overview

The final architecture looks like this:

                Internet
                     │
                     ▼
        Application Load Balancer
             (HTTP Port 80)
                     │
                     ▼
           Target Group (devops-tg)
                     │
                     ▼
         Ubuntu EC2 Instance (Nginx)

The Application Load Balancer receives incoming HTTP requests and forwards them to the registered EC2 instance through the Target Group.

Step 1: Create the Security Group

The first step was creating a custom Security Group named:

devops-sg

Inbound Rule:

Type Port Source
Custom TCP 80 Default Security Group

This configuration allows HTTP requests originating from the ALB to reach the EC2 instance securely.

Step 2: Launch the EC2 Instance

Next, I launched a new Ubuntu EC2 instance.

Configuration:

Setting Value
Instance Name devops-ec2
AMI Ubuntu
Instance Type t3.micro
Security Group devops-sg

Instead of installing software manually, I used User Data to automate the server configuration during instance launch.

Step 3: Attach the Security Group

While launching the EC2 instance, I attached the previously created security group:

devops-sg

This ensured that only the Application Load Balancer could communicate with the web server over HTTP.

Step 4: Configure User Data

The following script automatically installs and starts the Nginx web server.

#!/bin/bash

sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx

When the EC2 instance booted for the first time, AWS automatically executed this script.

As a result:

  • Nginx was installed

  • The service started automatically

  • The web server became ready without manual intervention

Step 5: Create the Application Load Balancer

After the EC2 instance was running, I created an Internet-facing Application Load Balancer.

Configuration:

Setting Value
Name devops-alb
Scheme Internet-facing
IP Type IPv4
Listener HTTP :80
Security Group Default Security Group

The ALB acts as the public entry point for client requests.

Step 6: Configure the ALB Security Group

The default Security Group attached to the ALB was configured to allow inbound HTTP traffic.

Type Port
HTTP 80

Step 7: Create the Target Group

The next step was creating a Target Group.

Configuration:

Setting Value
Name devops-tg
Target Type Instances
Protocol HTTP
Port 80

The Target Group acts as the bridge between the ALB and backend EC2 instances.

Step 8: Register the EC2 Instance

After creating the Target Group, I registered the EC2 instance.

Registered Target:

devops-ec2

Target Port:

80

Once registered, AWS automatically began performing health checks on the instance.

Step 9: Verify the Application

Finally, I opened the Application Load Balancer DNS name in the browser.

The default Nginx welcome page appeared successfully.

Welcome to nginx!

This confirmed that:

  • The ALB was reachable

  • Security Groups were configured correctly

  • The Target Group was healthy

  • The EC2 instance was serving HTTP traffic

  • Nginx was installed successfully using User Data

Conclusion

Day 36 focused on building a scalable and production-ready web architecture using Amazon EC2 and the Application Load Balancer (ALB).

By creating a dedicated security group, launching an Ubuntu instance with automated Nginx installation, configuring an Application Load Balancer, registering the EC2 instance in a Target Group, and validating traffic through the ALB DNS, I gained practical experience with one of the most commonly used architectures in AWS.

This hands-on exercise demonstrated how AWS Elastic Load Balancing improves availability, simplifies traffic management, and provides the foundation for scaling web applications across multiple EC2 instances.

More from this blog

A

Anand Raval

132 posts

I'm Anand Raval, a Cloud & DevOps Engineer with AWS Solutions Architect Associate (SAA-C03), Certified Kubernetes Administrator (CKA), and Azure Fundamentals (AZ-900) certifications. This blog covers AWS, Kubernetes, Terraform, CI/CD, cloud architecture, automation, cost optimization, troubleshooting guides, and hands-on DevOps projects.