How to Set Up a Load Balancer on AWS for High Availability.

How to Set Up a Load Balancer on AWS for High Availability.

Building highly available applications is no longer optional it’s expected. Whether you’re running a startup app or an enterprise system, downtime can cost users, revenue, and trust. One of the simplest and most effective ways to improve availability is by using a load balancer.

In this guide, you’ll learn how to set up a load balancer on AWS step by step, even if you’re a beginner. By the end, you’ll have a working setup that distributes traffic across multiple servers and keeps your application resilient.

What is a Load Balancer?

A load balancer acts as a traffic controller. Instead of sending all user requests to a single server, it distributes them across multiple servers.

Why this matters:

  • Prevents server overload
  • Improves application performance
  • Ensures high availability
  • Handles traffic spikes efficiently

On AWS, the most commonly used service is the Application Load Balancer (ALB), part of Elastic Load Balancing (ELB).

Prerequisites

Before we start, make sure you have:

  • An AWS account
  • Basic knowledge of cloud computing
  • Access to the AWS Management Console
  • At least two EC2 instances (for redundancy)

Step 1: Launch EC2 Instances

We’ll begin by setting up two servers that your load balancer will distribute traffic to.

Steps:

  1. Go to EC2 Dashboard
  2. Click Launch Instance
  3. Choose an Amazon Machine Image (AMI), like Amazon Linux
  4. Select instance type (t2.micro is fine for testing)
  5. Configure:
    • Allow HTTP (port 80) in security group
  6. Launch at least two instances

Step 2: Install a Web Server

Connect to each instance via SSH and install a simple web server.

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

Customize each server

On Instance 1:

echo “Hello from Server 1” | sudo tee /usr/share/nginx/html/index.html

On Instance 2:

echo “Hello from Server 2” | sudo tee /usr/share/nginx/html/index.html

This helps you verify traffic distribution later.

Step 3: Create a Target Group

A target group is a collection of servers that receive traffic from the load balancer.

Steps:

  1. Go to EC2 → Target Groups
  2. Click Create Target Group
  3. Choose:
    • Target type: Instances
    • Protocol: HTTP
    • Port: 80
  4. Give it a name (e.g., my-target-group)
  5. Register your EC2 instances

Step 4: Create an Application Load Balancer

Now we’ll create the load balancer itself.

Steps:

  1. Go to EC2 → Load Balancers
  2. Click Create Load Balancer
  3. Choose Application Load Balancer
  4. Configure:
    • Name: my-load-balancer
    • Scheme: Internet-facing
    • IP type: IPv4

Network mapping:

  • Select your VPC
  • Choose at least two subnets in different Availability Zones

Security group:

  • Allow HTTP (port 80)

Step 5: Configure Listeners and Routing

Listeners define how traffic is handled.

Default setup:

  • Protocol: HTTP
  • Port: 80
  • Forward to: your target group

Step 6: Register Targets

If not already done:

  • Add your EC2 instances to the target group
  • Ensure health checks are passing

Step 7: Configure Health Checks

Health checks ensure traffic only goes to healthy servers.

Default settings:

  • Protocol: HTTP
  • Path: /
  • Interval: 30 seconds

You can customize thresholds depending on your application.

Step 8: Access Your Load Balancer

Once created, AWS provides a DNS name like:

my-load-balancer-123456789.us-east-1.elb.amazonaws.com

Paste it into your browser.

What you should see:

Refreshing the page should alternate between:

  • “Hello from Server 1”
  • “Hello from Server 2”

That means your load balancer is working!

Step 9: Enable Auto Scaling (Optional but Recommended)

To make your system truly highly available, combine load balancing with Auto Scaling.

Benefits:

  • Automatically adds instances during high traffic
  • Removes instances when demand drops
  • Saves cost while maintaining performance

Step 10: Add HTTPS (SSL/TLS)

For production use, always secure your application.

Steps:

  1. Go to AWS Certificate Manager (ACM)
  2. Request a certificate
  3. Add HTTPS listener (port 443) to your load balancer
  4. Attach the certificate

Step 11: Monitor Your Load Balancer

Use CloudWatch to track performance.

Key metrics:

  • Request count
  • Latency
  • Healthy host count
  • HTTP error rates

Step 12: Clean Up Resources

To avoid charges:

  • Terminate EC2 instances
  • Delete load balancer
  • Delete target groups

Key Concepts Recap

  • Load Balancer: Distributes traffic across servers
  • Target Group: Group of instances receiving traffic
  • Listener: Defines how requests are routed
  • Health Check: Ensures only healthy servers receive traffic

Common Beginner Mistakes

1. Instances not in multiple AZs

High availability requires multiple availability zones.

2. Security group misconfiguration

Ensure ports 80/443 are open.

3. Health checks failing

Incorrect path or port can mark instances unhealthy.

4. Not using Auto Scaling

Limits your system’s ability to handle traffic spikes.

Real-World Architecture Example

A typical production setup:

  • Load Balancer (ALB)
  • Auto Scaling Group (multiple EC2 instances)
  • RDS database
  • CloudWatch monitoring
  • Route 53 for DNS

Final Thoughts

Setting up a load balancer on AWS is one of the most important steps toward building a reliable, scalable application.

At a high level, the process is simple:

  1. Launch multiple servers
  2. Group them into a target group
  3. Create a load balancer
  4. Route traffic intelligently
  5. Monitor and scale

Once you understand this workflow, you can design systems that handle real-world traffic with confidence.

High availability isn’t just about uptime it’s about delivering a consistent experience to your users, no matter what happens behind the scenes.

shamitha
shamitha
Leave Comment
Share This Blog
Recent Posts
Get The Latest Updates

Subscribe To Our Newsletter

No spam, notifications only about our New Course updates.

Enroll Now
Enroll Now
Enquire Now