Configure Auto Scaling with Load balancer

Dipali Kulshrestha
3 min readMay 25, 2021

--

Scenario: we want to auto-scale web application which is running behind a load balancer on two EC2 servers. The moment EC2 gets CPU usage more than 60%, we want to add two more servers.

Steps:

  1. Create Application Load Balancer
  2. Create Launch Configuration
  3. Create Auto Scaling Group
  4. Test Auto Scaling

Step1: Create Application Load Balancer

Select a Security Group where you have Port 80 open

Don’t register any target (as it will be registered via auto scaling) and create.

Step2: Create Launch Template

Provide user data script in Advanced

#!/bin/sh
sudo yum update -y
sudo yum install httpd -y
sudo service httpd start
chkconfig httpd on
echo "Hello World from $(hostname -f)" > /var/www/html/index.html
echo "Healthy" > /var/www/html/hc.html

Step 3: Create Auto Scaling Group for Launch Template created in Step 2

the cooldown period helps to ensure that your Auto Scaling group doesn’t launch or terminate additional instances before the previous scaling activity takes effect. You can configure the length of time based on your instance warmup period or other application needs.

Warm-up value for Instances allows you to control the time until a newly launched instance can contribute to the CloudWatch metrics, so when warm-up time has expired, an instance is considered to be a part Auto Scaling group and will receive traffic

After it is created you should see 2 instances running in EC2.

Check your Application via ELB DNS and EC2, HealthCheck via Public DNS e.g.

http://webapplb-1654405070.us-east-1.elb.amazonaws.com/

http://ec2-34-236-187-45.compute-1.amazonaws.com/

http://ec2-34-236-187-45.compute-1.amazonaws.com/hc.html

Step4: Test Autoscaling

Login to EC2 instance

Install stress utility to generate cpu load

sudo amazon-linux-extras install epel -y
sudo yum install stress -y

Generate load

sudo stress --cpu 6 --timeout 180

Monitor and check if new instances are created.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Dipali Kulshrestha
Dipali Kulshrestha

No responses yet

Write a response