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
Log in to the AWS Management Console.
Navigate to the EC2 dashboard.
Click on the “Launch Templates” option in the left-side navigation bar.
Click the “Create Launch Template” button.
Provide a name and description for the template, and select the AMI you want to use. In my case, Amazon Linux 2
Configure the instance type to use t2.micro to make use of the AWS free tier, network settings, storage, and other settings as desired.
Save the launch template.
Navigate to the EC2 dashboard.
Click on the “Auto Scaling Groups” option in the left-side navigation bar.
Click the “Create Auto Scaling Group” button.
Choose the launch template you just created.
Provide a name for the group, the desired group size, and the network settings.
Define the scaling policies by setting conditions that will trigger the scaling of EC2 instances.
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.
Review the settings and launch the ASG.
Step 2: Creating an Application Load Balancer (ALB)
Log in to the AWS Management Console.
Navigate to the EC2 dashboard.
Click on the “Load Balancers” option in the left-side navigation bar.
Click the “Create Load Balancer” button.
Choose “Application Load Balancer” as the type of load balancer.
Give the load balancer a name and select the VPC and subnets you want to use.
Configure the security settings by creating a security group and choosing the protocols and ports to allow.
Add the target groups that you want to use with the ALB by selecting the option 'Create target group'
Define the routing rules by setting conditions that will determine which target group will receive traffic
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
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.
Connect to the EC2 instance using EC2 Instance Connect
Install the stress utility by running the following command:
sudo amazon-linux-extras install epel -y sudo yum install stress
Run the stress test by executing the following command:
stress --cpu 4 --timeout 300
This will simulate a high CPU load on the EC2 instance for 300 seconds with 4 CPU cores.
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.
We can see how our solutions added a new instance to cope with the increased load created by the stress test
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.