Overview: Understanding Application Load Balancer (ALB)

An Application Load Balancer (ALB) is a service provided by Amazon Web Services (AWS) that distributes incoming application traffic across multiple targets, such as EC2 instances, in multiple Availability Zones. This helps achieve fault tolerance and improve application availability. The ALB operates at the OSI model’s application layer (Layer 7) and supports content-based and advanced request routing.

Core Features of ALB

  1. Content-Based Routing: ALB can route traffic to different targets based on the request’s content.
  2. SSL Termination: ALB can handle SSL/TLS termination and offload the task from your backend servers.
  3. WebSocket Support: ALB supports WebSockets, enabling real-time communication for your applications.
  4. Enhanced Metrics: ALB provides detailed CloudWatch metrics to monitor the health and performance of your application.
  5. Health Checks: ALB regularly checks targets’ health and ensures that traffic is only routed to healthy targets.

Introduction to Auto Scaling Group (ASG)

An Auto Scaling Group (ASG) is a feature of AWS that allows you to automatically scale your EC2 instance capacity up or down based on defined conditions. This ensures you have the suitable computing capacity to handle your application’s load.

Key Characteristics of ASG

  1. Automatic Scaling: Automatically adjusts the number of EC2 instances based on demand.
  2. Health Monitoring: Continuously monitors the health of running instances and replaces unhealthy ones.
  3. Elasticity: Ensures your application has the optimal number of instances to meet its performance requirements.
  4. Integration with ALB: Works seamlessly with ALB to distribute traffic across dynamically scaled instances.

Step-by-Step Instructions

5.1: Logging into the AWS Management Console

  1. Navigate to the AWS Management Console.
  2. Enter your credentials to log in.

5.2: Configuring Security Group for the Load Balancer

  1. In the console, go to the EC2 Dashboard.
  2. Click on Security Groups under the Network & Security section.
  3. Create a new security group and set the inbound rules for HTTP (port 80) and HTTPS (port 443).

5.3: Setting Up Security Group for the Launch Template

  1. Create another security group for your EC2 instances.
  2. Allow inbound traffic from the ALB security group and the necessary outbound traffic.

5.4: Generating a Key Pair for the Launch Template

  1. Go to the Key Pairs section under Network & Security.
  2. Click on Create Key Pair and download the private key file.

5.5: Building the Launch Template

  1. In the EC2 Dashboard, click on Launch Templates.
  2. To create a new launch template, specify the AMI, instance type, security group, and critical pair created earlier.

5.6: Establishing Target Group and Load Balancer

  1. Navigate to the Load Balancers section and create a new load balancer.
  2. Choose Application Load Balancer and configure it with the security group created for the ALB.
  3. Set up a target group and register your EC2 instances with it.

5.7: Setting Up the Auto Scaling Group

  1. Go to the Auto Scaling Groups section and create a new group.
  2. Choose the launch template created earlier and associate it with the target group.
  3. Define the scaling policies based on your application’s needs.

5.8: Accessing EC2 Instance via SSH and Installing Stress Tool

  1. Use the key pair to SSH into one of the EC2 instances.
  1. Install a stress testing tool like stress to simulate load:

    sudo yum install -y stress

5.9: Verifying Auto Scaling Group and Load Balancer Functionality

  1. Simulate load on your EC2 instances using the stress tool:

    stress –cpu 8 –timeout 300
  2. Monitor the ASG to see if it launches additional instances.
  3. Check the ALB to ensure it is distributing traffic across the instances.

Conclusion

Setting up an AWS Application Load Balancer and Auto Scaling Group is essential for ensuring your applications’ high availability and scalability. Following the steps outlined in this guide, you can efficiently distribute incoming traffic and dynamically scale your infrastructure based on demand.

References

Attach an Elastic Load Balancing load balancer to your Auto Scaling group

Set up a scaled and load-balanced application