DEV Community

Cover image for βš–οΈ AWS 124: Balancing the Load - Setting Up an Application Load Balancer (ALB)
Hritik Raj
Hritik Raj

Posted on

βš–οΈ AWS 124: Balancing the Load - Setting Up an Application Load Balancer (ALB)

AWS

🌐 Traffic Control: Routing Requests with AWS ALB

Hey Cloud Architects πŸ‘‹

Welcome to Day 24 of the #100DaysOfCloud Challenge!
Today, we are taking the Nautilus application to the next level. Instead of hitting our EC2 instance directly, we are placing an Application Load Balancer (ALB) in front of it. This is the foundation for scaling and fault tolerance.


🎯 Objective

  • Create a Security Group (nautilus-sg) to allow public HTTP traffic.
  • Provision an Application Load Balancer named nautilus-alb.
  • Create a Target Group named nautilus-tg and register the nautilus-ec2 instance.
  • Ensure traffic flows from the ALB (Port 80) to the Nginx server (Port 80).

πŸ’‘ Why Use an ALB?

Directly exposing an EC2 instance to the internet is rarely done in production.

πŸ”Ή Key Concepts

  • Single Entry PointΒ Β 
    The ALB provides one DNS name for your users, even if you have 10 servers running behind it.

  • Health ChecksΒ Β 
    The ALB constantly "pings" your server. If Nginx crashes, the ALB stops sending traffic there, preventing users from seeing error pages.

  • Security AbstractionΒ Β 
    Your EC2 instance can stay in a private subnet while the ALB sits in the public subnet, acting as a shield.


πŸ› οΈ Step-by-Step: The ALB Workflow

We’ll move from Security β†’ Target Groups β†’ Load Balancer.


πŸ”Ή Phase A: Configure Security Groups

  • Create nautilus-sg: This group is for the ALB. Add an Inbound Rule for HTTP (Port 80) from 0.0.0.0/0 (Everywhere).

  • Update Instance SG: Ensure the security group attached to nautilus-ec2 allows traffic on Port 80, ideally only from the ALB's security group for maximum security.


πŸ”Ή Phase B: Create the Target Group (TG)

  • Initiate nautilus-tg: Choose "Instances" as the target type.
  • Protocol: Set to HTTP on Port 80.
  • Register Targets: Select nautilus-ec2 and click "Include as pending below."

⚠️ Lesson Learned: Ensure your Target Group includes the same Availability Zones as your EC2 instance!


πŸ”Ή Phase C: Launch the Application Load Balancer

  • Name: nautilus-alb.
  • Scheme: Internet-facing.
  • Network Mapping: Select at least two Availability Zones (AWS requirement for high availability).
  • Security Groups: Attach the nautilus-sg you created in Phase A.
  • Listeners and Routing: Set the listener to HTTP:80 and forward to your nautilus-tg.


βœ… Verify Success

Once the ALB state is Active, follow these steps:

  1. Copy the DNS name of your ALB (e.g., nautilus-alb-12345.us-east-1.elb.amazonaws.com).

  2. Paste it into your browser.

  3. πŸŽ‰ If you see the Nginx Welcome Page, mission accomplished!


πŸ“ Key Takeaways

  • πŸš€ Patience is Key: When you first register an instance, the status shows "Unused" or "Initial". You must wait for the health checks to pass before it shows "Healthy".
  • 🌍 AZ Awareness: As discovered during the task, an ALB must be configured with the correct subnets/AZs to reach its targets.
  • πŸ” Security Chain: Traffic flows: User β†’ ALB Security Group β†’ EC2 Security Group. Both must be open on the correct ports.

🚫 Common Mistakes

  • AZ Mismatch: Creating an ALB in AZ us-east-1a while your instance is in us-east-1b without selecting both in the ALB settings.
  • Health Check Failure: If your Nginx service isn't running, the ALB will mark the target as "Unhealthy" and won't route traffic.
  • Missing Subnets: An internet-facing ALB requires a public subnet with an Internet Gateway.

🌟 Final Thoughts

Building an ALB setup is a huge leap toward becoming a Cloud Engineer. You’ve moved from "running a server" to "designing a system." This setup allows you to add more instances later without changing the URL your users see!


πŸ”— Let’s Connect

Top comments (0)