DEV Community

Cover image for AWS Elastic Load Balancers (ELB) - Week Fourteen
Shubham Murti
Shubham Murti

Posted on

AWS Elastic Load Balancers (ELB) - Week Fourteen

Hello Community! 🌟

In this week's deep dive, we explored essential components of Amazon Web Services (AWS), focusing on Elastic Load Balancers (ELB), including Classic Load Balancers (CLB), Application Load Balancers (ALB), and Network Load Balancers (NLB). Understanding these load balancers is crucial for effectively managing traffic, ensuring high availability, and maintaining fault tolerance within your cloud infrastructure. Here's a detailed explanation of what I learned and how you can implement these concepts to enhance the performance and reliability of your AWS deployments.


Understanding the Need for a Load Balancer

Imagine your application typically handles around 1,000 requests per day, but suddenly, that number spikes to 5,000. Without a load balancer, this surge could overwhelm your application, leading to slower response times or even a complete system crash. A load balancer steps in to distribute these incoming requests evenly across multiple servers, ensuring your application remains responsive and reliable.


What is a Load Balancer?

A load balancer is a device or software that acts as a reverse proxy, distributing network or application traffic across multiple servers. This helps ensure that no single server becomes overwhelmed with too much traffic, improving the availability and responsiveness of applications.


AWS Load Balancer Types

AWS provides four main types of load balancers, each tailored to different layers of the OSI model and application requirements:

  • Application Load Balancer (ALB): Operates at Layer 7 (Application Layer) and is designed for HTTP and HTTPS traffic. It supports advanced routing, SSL termination, and WebSocket support.

  • Network Load Balancer (NLB): Operates at Layer 4 (Transport Layer) and handles TCP, UDP, and TLS traffic. It is optimized for handling sudden and volatile traffic patterns.

  • Gateway Load Balancer (GLB): Also operates at Layer 7, integrating with third-party network appliances such as firewalls, intrusion detection systems (IDS), and intrusion prevention systems (IPS).

  • Classic Load Balancer (CLB): Operates at both Layer 4 (Transport Layer) and Layer 7 (Application Layer). It is the original AWS load balancer, now largely considered outdated in favor of ALB and NLB.


Classic Load Balancer (CLB)

What is a Classic Load Balancer?

The Classic Load Balancer is the first generation of load balancers provided by AWS. It can handle both Layer 4 and Layer 7 traffic but lacks many of the advanced features offered by ALB and NLB. While it's not recommended for new deployments, understanding CLB is crucial for managing legacy systems.

Steps to Create a Classic Load Balancer:

  1. Define Load Balancer:

    • Navigate to the EC2 console.
    • Click on "Load Balancers" and select "Create Load Balancer."
    • Choose "Classic Load Balancer" and name it.
    • Configure the listener settings (e.g., HTTP on port 80).
  2. Assign Security Group:

    • Select or create a security group that allows traffic to and from the load balancer.
  3. Configure Security Settings:

    • Skip this step if SSL is not required. Otherwise, set up the SSL certificate.
  4. Configure Health Check:

    • Set up health checks to monitor the health of EC2 instances.
    • Specify the ping path, protocol, and thresholds.
  5. Add EC2 Instances:

    • Select the EC2 instances you want to include in the load balancing group.
  6. Add Tags:

    • Optionally, add tags to help manage your resources.
  7. Review and Create:

    • Review all settings and click "Create" to launch the Classic Load Balancer.

Note: Once set up, the load balancer can be accessed via its DNS name. It's not recommended to access the EC2 instances directly through their public IPs, as all traffic should route through the load balancer for optimal performance and security.

Managing EC2 Instance Access

To ensure that all requests pass through the load balancer, I adjusted the security groups for the EC2 instances, removing direct HTTP access. This effectively blocked direct access, ensuring that all traffic goes through the load balancer.


Application Load Balancer (ALB)

Unlike the CLB, the Application Load Balancer sends traffic to target groups rather than directly to EC2 instances. This allows for more advanced routing options, like path-based routing.

What is an Application Load Balancer?

The Application Load Balancer is designed to handle HTTP and HTTPS traffic at Layer 7. It offers advanced features like content-based routing, SSL offloading, and WebSocket support.

Steps to Create an Application Load Balancer:

  1. Create a Target Group:

    • Navigate to the "Target Groups" dashboard.
    • Click on "Create Target Group."
    • Choose the target type (e.g., Instances, IP addresses).
    • Set up the health check parameters, including protocol and path.
  2. Create the Load Balancer:

    • Go to the "Load Balancers" dashboard and click "Create Load Balancer."
    • Choose "Application Load Balancer."
    • Specify the load balancer name, VPC, and subnets.
    • Configure listeners (e.g., HTTP or HTTPS).
  3. Configure Security Settings:

    • Attach a security group that allows traffic on the required ports.
  4. Register Targets:

    • Select the EC2 instances or targets to include in the target group.
  5. Configure Listeners and Rules:

    • Set up rules to direct traffic based on the URL path, host headers, or query strings.
  6. Review and Create:

    • Review the configuration and click "Create" to deploy the ALB.

Path-Based Routing

Path-based routing allows you to route requests to different target groups based on the URL path. For example, requests to /api/* could be routed to one target group, while requests to /static/* are routed to another.

Retrieving Client IP Address

A challenge I encountered was obtaining the client IP address instead of the load balancer's IP when checking logs. By modifying the Nginx configuration on the EC2 instance, I added a custom log format to capture the client's IP address.


Network Load Balancer (NLB)

The NLB operates at Layer 4 and is designed for high-performance, low-latency traffic. Like the ALB, it requires configuring a load balancer, setting up a security group, and then cleaning up instances after testing.

What is a Network Load Balancer?

The Network Load Balancer is optimized for handling high-volume TCP, UDP, and TLS traffic at Layer 4. It is designed for extreme performance and can handle millions of requests per second.

Steps to Create a Network Load Balancer:

  1. Choose the Load Balancer Type:

    • Navigate to the "Load Balancers" dashboard.
    • Click "Create Load Balancer" and select "Network Load Balancer."
  2. Configure Load Balancer:

    • Specify the load balancer name, VPC, and subnets.
    • Select the listener port and protocol.
  3. Configure Security Settings:

    • Attach a security group that allows traffic on the required ports.
  4. Register Targets:

    • Select the EC2 instances or other resources that will receive traffic from the NLB.
  5. Review and Create:

    • Review the configuration and click "Create" to deploy the NLB.

Advanced Features: Stickiness and Custom Page Routing

I also explored stickiness in the Application Load Balancer, which ensures that requests from the same client are consistently routed to the same server. This is useful for maintaining session data. Additionally, I learned about configuring custom error pages and SSL settings, as well as enabling cross-zone load balancing to distribute traffic across multiple Availability Zones.


Closure

AWS Elastic Load Balancers play a vital role in managing traffic and ensuring the availability of your applications. Whether you're using the Classic Load Balancer for legacy systems, the Application Load Balancer for web traffic, or the Network Load Balancer for high-performance TCP/UDP applications, understanding how to configure and optimize these load balancers is crucial for maintaining a resilient cloud infrastructure. By leveraging these tools, you can achieve higher availability, fault tolerance, and efficient resource utilization across your AWS environment.

Stay tuned for more updates next week!

Shubham Murti — Aspiring Cloud Security Engineer | Weekly Cloud Learning !!

Let’s connect: Linkdin, Twitter, Github

Top comments (0)