Hands-On Labs - Creating an Auto Scaling Group and Application Load Balancer in AWS

Hands-On Labs - Creating an Auto Scaling Group and Application Load Balancer in AWS

As a cloud engineer, it's important to have a solid understanding of the tools and technologies that can help ensure the high availability and scalability of applications. In this article, I'll focus on two such components in Amazon Web Services (AWS): Auto Scaling Groups and Application Load Balancers.

Auto Scaling Groups (ASGs) are a key component of AWS auto-scaling, which helps automatically adjust the number of EC2 instances in response to changes in demand. With an ASG, you can ensure that your application always has the resources it needs to meet user demand, even during spikes in traffic. This can help reduce downtime, improve the user experience, and ultimately increase the reliability of your application.

Application Load Balancers (ALBs), on the other hand, are a type of load balancer that can be used to distribute incoming traffic to multiple targets, such as EC2 instances, containers, and Lambda functions. With an ALB, you can ensure that your application is always accessible, even during periods of high traffic. Additionally, ALBs offer advanced routing capabilities, such as path-based routing, that can help you distribute traffic in a more granular manner.

Now that I've briefly introduced Auto Scaling Groups and Application Load Balancers, let's dive into the steps for creating each component in AWS.

Step 1: Creating an Auto Scaling Group (ASG) using a Launch Template

  1. Log in to the AWS Management Console.

  2. Navigate to the EC2 dashboard.

  3. Click on the “Launch Templates” option in the left-side navigation bar.

  4. Click the “Create Launch Template” button.

  5. Provide a name and description for the template, and select the AMI you want to use. In my case, Amazon Linux 2

  6. Configure the instance type to use t2.micro to make use of the AWS free tier, network settings, storage, and other settings as desired.

  7. Save the launch template.

  8. Navigate to the EC2 dashboard.

  9. Click on the “Auto Scaling Groups” option in the left-side navigation bar.

  10. Click the “Create Auto Scaling Group” button.

  11. Choose the launch template you just created.

  12. Provide a name for the group, the desired group size, and the network settings.

  13. Define the scaling policies by setting conditions that will trigger the scaling of EC2 instances.

  14. Set the health check grace period, which is the time that Auto Scaling will wait after a new EC2 instance is in service before checking its health.

  15. Review the settings and launch the ASG.

Step 2: Creating an Application Load Balancer (ALB)

  1. Log in to the AWS Management Console.

  2. Navigate to the EC2 dashboard.

  3. Click on the “Load Balancers” option in the left-side navigation bar.

  4. Click the “Create Load Balancer” button.

  5. Choose “Application Load Balancer” as the type of load balancer.

  6. Give the load balancer a name and select the VPC and subnets you want to use.

  7. Configure the security settings by creating a security group and choosing the protocols and ports to allow.

  8. Add the target groups that you want to use with the ALB by selecting the option 'Create target group'

  9. Define the routing rules by setting conditions that will determine which target group will receive traffic

  10. Review the settings and create the ALB.

Now that you have created both an Auto Scaling Group and an Application Load Balancer, you can test their functionality and performance. One way to do this is by conducting a stress test.

Step 3: Stress Testing the ASG and ALB

  1. Navigate to the EC2 dashboard and you should see the desired number of EC2 instances defined in the Auto Scaling Group. In my case, 2 EC2 instances.

  2. Connect to the EC2 instance using EC2 Instance Connect

  3. Install the stress utility by running the following command:

     sudo amazon-linux-extras install epel -y  
     sudo yum install stress
    
  4. Run the stress test by executing the following command:

     stress --cpu 4 --timeout 300
    
  5. This will simulate a high CPU load on the EC2 instance for 300 seconds with 4 CPU cores.

  6. Observe the behaviour of the ASG and ALB as the stress test is executed. The ASG should automatically increase the number of EC2 instances to handle the increased load, and the ALB should distribute incoming traffic evenly among the available EC2 instances.

  7. We can see how our solutions added a new instance to cope with the increased load created by the stress test

  8. Analyze the results of the stress test and make any necessary adjustments to the ASG and ALB configuration to optimize performance.

By following the steps outlined above, you now have the tools to create an Auto Scaling Group and Application Load Balancer in AWS that can support your applications' high availability and scalability. By conducting a stress test, you can validate the functionality of these components and make any necessary optimizations to improve performance. As a cloud engineer, it's crucial to have a thorough understanding of the tools and technologies that can aid you in achieving your goals, and Auto Scaling Groups and Application Load Balancers are two of the most important components in this regard.

Stay tuned for more updates and exciting developments in the world of cloud engineering.

Did you find this article valuable?

Support Esteban Moreno by becoming a sponsor. Any amount is appreciated!