Auto Scaling with an Application Load Balancer

mahpara jabbarmahpara jabbar
4 min read

This lab teaches how to set up an Auto Scaling infrastructure in AWS, including creating an AMI, configuring a load balancer, and implementing an Auto Scaling group. It demonstrates dynamic resource scaling based on demand to ensure application availability and efficient traffic distribution. The lab also tests scaling by increasing load and verifying load balancer functionality.

Summary:

Step 1: Create an AMI from Web Server 1

Step 2: Create a Load Balancer

Step 3: Create a Launch Template

Step 4: Create an Auto Scaling Group

Step 5: Verify Load Balancer Functionality

Step 6: Test Auto Scaling

Step 7: Terminate Web Server 1

Step 1: Create an AMI from Web Server 1

  1. Go to EC2 Dashboard:
    Search for EC2 in the AWS Management Console.

  2. Select Instance:
    In the Instances section, find Web Server 1 (ensure it's in the Running state).

  3. Create Image:

    • Select Web Server 1.

    • Choose Actions > Image and templates > Create image.

    • Set Image name: Web Server AMI.

    • Optional: Add Image description: Lab AMI for Web Server.

    • Click Create image.

  4. Note AMI ID:
    Copy the AMI ID for use when launching the Auto Scaling group later.

Step 2: Create a Load Balancer

  1. Navigate to Load Balancers:
    In the EC2 Dashboard, go to Load Balancers under the Load Balancing section.

  2. Create Load Balancer:

    • Click Create load balancer.

    • Choose Application Load Balancer.

    • Set Load balancer name: LabELB.

  3. Network Configuration:

    • Select Lab VPC.

    • Map to Public Subnet 1 and Public Subnet 2 for availability zones.

  4. Security Group:

    • Remove the default security group.

    • Select Web Security Group (preconfigured for HTTP access).

  5. Create Target Group:

    • Click Create target group (opens a new tab).

    • Choose Instances as the target type.

    • Set Target group name: lab-target-group.

    • Click Next and Create target group.

  6. Assign Target Group to Load Balancer:

    • Return to the Load Balancer tab and Refresh the target groups.

    • Select lab-target-group for the Forward to action.

  7. Create Load Balancer:
    Click Create load balancer and copy the DNS name.

Step 3: Create a Launch Template

  1. Access Launch Templates:
    In the EC2 Dashboard, go to Launch Templates.

  2. Create Launch Template:

    • Set Launch template name: lab-app-launch-template.

    • Add a Description: A web server for the load test app.

    • Check the box for Auto Scaling guidance.

  3. AMI and Instance Type:

    • Choose the My AMIs tab and select Web Server AMI.

    • Set the Instance type to t3.micro.

  4. Security Group:

    • Select Web Security Group.
  5. Create Template:
    Click Create launch template.

Step 4: Create an Auto Scaling Group

  1. Create Auto Scaling Group:

    • Select lab-app-launch-template from the launch template list.

    • Choose Actions > Create Auto Scaling group.

    • Set Auto Scaling group name: Lab Auto Scaling Group.

  2. Network Configuration:

    • Select Lab VPC.

    • Assign Private Subnet 1 and Private Subnet 2.

  3. Attach Load Balancer:

    • Choose Attach to an existing load balancer.

    • Select lab-target-group | HTTP.

  4. Health Check:
    Set Health check type to ELB.

  5. Group Size and Scaling Policy:

    • Set Desired capacity: 2.

    • Set Minimum capacity: 2.

    • Set Maximum capacity: 4.

    • Enable Target tracking scaling policy for Average CPU utilization and set the target to 50%.

  6. Tags:

    • Add a Tag:

      • Key: Name,

      • Value: Lab Instance.

  7. Create Auto Scaling Group:
    Finish by clicking Create Auto Scaling group.

Step 5: Verify Load Balancer Functionality

  1. Check Instances:

    • Go to Instances in the EC2 Dashboard.

    • Ensure two Lab Instances are running.

  2. Check Target Health:

    • In Load Balancing > Target Groups, find lab-target-group.

    • Verify that both Lab Instances show a Healthy status.

  3. Access Application:
    Use the load balancer DNS name to check if the Load Test app is running.

Step 6: Test Auto Scaling

  1. Access CloudWatch:
    In the AWS Console, search for CloudWatch.

  2. Check Alarms:

    • In Alarms, locate the AlarmHigh (CPU utilization > 50%).

    • Ensure the state is OK.

  3. Generate Load:

    • Open the Load Test tab from the web application.

    • Trigger high CPU load by selecting Load Test.

  4. Monitor Scaling:

    • In CloudWatch, check the AlarmHigh status, which should change to In alarm.

    • Auto Scaling should add instances as CPU load increases.

Step 7: Terminate Web Server 1

  1. Terminate Instance:

    • Go to EC2 Dashboard > Instances.

    • Select Web Server 1.

    • From the Instance state menu, choose Terminate instance.

0
Subscribe to my newsletter

Read articles from mahpara jabbar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

mahpara jabbar
mahpara jabbar