In this hands-on lab scenario, you’re a cloud network engineer working for an organization that sells products online. You’re gearing up for the annual sale that provides a 50% discount on all items. This sale drives a ton of traffic and revenue. Your job is to ensure the website doesn’t go down and is able to handle every request efficiently. In this lab, you will integrate two powerful AWS services: Elastic Load Balancers and Auto Scaling groups. Specifically, you will create an Auto Scaling group of EC2 instances operating as web servers and then configure an Application Load Balancer to load balance between the instances inside that Auto Scaling group. After everything is set up, you’ll simulate stress tests on the EC2 instances to confirm the Auto Scaling group works as expected.
Successfully complete this lab by achieving the following learning objectives:
- Create an Application Load Balancer
Navigate to EC2 > Load Balancers.
Click Create Load Balancer.
Click the Create button under the Application Load Balancer and set the following values:
- Name: HOLALB
- Scheme: internet-facing
- IP address type: ipv4
- Load Balancer Protocol: HTTP
- Port: 80
- Select the VPC.
- Add the us-east-1a and us-east-1b AZs to your ALB.
Click Next: Configure Security Settings
Note: Skip this screen, as we are not using HTTPS.
Click Next: Configure Security Groups.
Select to Create a new security group for your ALB, and set the following values:
- Name: ALBSG
- Description: ALBSG
- The default value allows standard HTTP traffic from 0.0.0.0/0 and ::/0 (IPV6), so leave as it.
Click Next: Configure Routing and enter the following values:
- Name: ALBTG
- Target type: Instance
- Protocol: HTTP
- Port: 80
Expand Advanced health check settings, and reduce the healthy and unhealthy threshold checks down to 2.
- This means the load balancer can respond faster and instances come into service and vice versa.
Click Next: Register Targets.
Click Next: Review.
Make a note of the DNS name associated with the load balancer and open in a new browser tab. You should see a 503 error since we don’t have any operational EC2 instances associated with the load balancer.
- Create a Launch Template
Create an SSH key pair that the EC2 instances will use to control access. We will use the key pair to connect to the EC2 instances in order to perform load testing:
- Navigate to EC2 > Network & Security > Key Pairs.
- Click Create Key Pair.
- Call it ALBKP, and download the file to your local machine.
Create a security group for EC2 instances. This security group will allow us to SSH into the instances and it will allow the ALB to point frontend connections to the instances over port 80.
- Navigate to EC2 > Network & Security > Security Groups.
- Click Create Security Group.
- The name and description are EC2WEBSG.
- Set the VPC to the lab VPC.
- Add a rule allowing SSH from 0.0.0.0/0 and ::/0 (IPV6).
- Add a rule allowing HTTP from the Security Group ID of the security group for the ALB created in the previous video.
- Create the security group.
Create a launch template that will be used by the Auto Scaling group. The launch template defines what the instances are and how they are created.
Navigate to EC2 > Instances > Launch Templates.
Create a new template, and call it HOLLT for the name and description.
Search for "AMI", and pick the Amazon Linux 2 AMI (64-bit x86).
Set the instance type as t2.micro.
Select the key pair you created earlier.
The network type is VPC.
Select the EC2WEBSG security group you created earlier.
Storage should automatically be populated with a volume, so leave that as default and don’t add anything to the network section.
Expand Advanced Details, and paste the user data (provided on the lab page) in the box.
Note: These are commands to install a web server and download website content.
Click Create Launch Template.
- Create an Auto Scaling Group
Note: Make sure the load balancer is ready at this point.
- EC2 > Auto Scaling > Auto Scaling Groups
- Click Create Auto Scaling group.
- Call the group HOLASG.
- Select Launch Template, and choose the template you just created.
- Select Adhere to Launch Template.
- Pick the VPC from the lab environment, and select
- Click Next.
- Check Enable load balancing.
- Select target group ALBTG.
- Leave the default for Health checks.
- Select Enable group metrics collection with CloudWatch.
- For Group Size, enter the following values:
- Desired Capacity: 2
- Minimum Capacity: 2
- Maximum Capacity: 6
- For Scaling Policies, select Target tracking scaling policy and enter the following values:
- Scaling Policy Name: Target Tracking Policy
- Metric type: Average CPU utilization
- Target value: 30
- Instances need: 300
- Click Next.
- Click Create Auto Scaling Group.
Attempt to Connect to Website
Press Shift+Refresh to access the simple website.
- Test Horizontal Scaling
- Connect to one of the EC2 instances via SSH.
- Copy the connection string.
.pemkey pair file before running the connection string.
- Install the stress test application (using the commands provided on the lab page).
- Run the stress test on the EC2 instance (using the command provided on the lab page).
- After a few minutes, watch the number of instances increase. It enacts the scale-out policy.
- After a few minutes, stop the stress test. It enacts the scale-in policy.