Understanding AWS Load Balancing - Notes By ShariqSP

Understanding AWS Load Balancing

AWS (Amazon Web Services) Load Balancing is a key component for distributing incoming application traffic across multiple targets, such as EC2 instances, containers, or IP addresses. This ensures high availability, fault tolerance, and scalability of applications.

Key Concepts in AWS Load Balancing

  • Elastic Load Balancer (ELB): A managed service that automatically distributes incoming application traffic. AWS offers three types of ELBs:
    • Application Load Balancer (ALB): Operates at the application layer (Layer 7). Ideal for HTTP/HTTPS traffic and provides advanced routing based on URL, hostname, or headers.
    • Network Load Balancer (NLB): Operates at the transport layer (Layer 4). Suitable for ultra-low latency and handling millions of requests per second.
    • Gateway Load Balancer (GWLB): Designed for deploying, scaling, and managing third-party virtual appliances.
  • Target Groups: A collection of resources (e.g., EC2 instances, IPs, or Lambda functions) that receive traffic from the load balancer.
  • Health Checks: Periodic checks performed by the load balancer to ensure that targets are healthy and can handle traffic.
  • Listeners: Defines how the load balancer forwards traffic. A listener is configured with a protocol and port (e.g., HTTP:80 or HTTPS:443).

Scenario: Load Balancing a Web Application Across EC2 Instances

Let’s consider a scenario where you want to distribute traffic to a web application hosted on multiple EC2 instances in different availability zones for better availability and fault tolerance.

Step-by-Step Procedure

  1. Launch EC2 Instances:

    Launch at least two EC2 instances in different availability zones within the same region. Ensure that these instances are configured with your web application and are part of the same security group allowing HTTP/HTTPS traffic.

  2. Create a Target Group:
    1. Navigate to the EC2 dashboard in the AWS Management Console.
    2. Under the "Load Balancing" section, select "Target Groups" and click "Create target group."
    3. Choose the target type (e.g., Instances) and configure the protocol (HTTP/HTTPS) and port (e.g., 80 for HTTP).
    4. Register the EC2 instances by selecting them from the list.
  3. Create an Application Load Balancer:
    1. In the EC2 dashboard, go to "Load Balancers" and click "Create Load Balancer."
    2. Select "Application Load Balancer" and configure the following:
      • Name: Provide a unique name for the ALB.
      • Scheme: Choose "Internet-facing" for public access or "Internal" for private access.
      • Network Mapping: Select the VPC and at least two availability zones.
    3. Configure a listener for HTTP or HTTPS traffic and associate it with the target group created earlier.
    4. Review and create the ALB.
  4. Configure Health Checks:

    Ensure that the health check settings in the target group match the application’s health check endpoint. For example, use HTTP:80 and a specific URL path like /health.

  5. Test the Load Balancer:

    Obtain the DNS name of the ALB from the AWS console and use it to test the application in a browser. Traffic should be distributed across the EC2 instances.

Benefits of AWS Load Balancing

  • High Availability: Traffic is distributed across multiple targets and availability zones.
  • Fault Tolerance: Automatic health checks ensure that traffic is routed only to healthy targets.
  • Scalability: Automatically adjusts to varying traffic loads.
  • Security: Integration with AWS Certificate Manager for SSL/TLS termination.

Common Terms Explained

  • Elasticity: The ability to scale resources up or down based on demand.
  • VPC: Virtual Private Cloud, an isolated network within AWS.
  • Availability Zone: A distinct data center within a region, designed for fault isolation.