EC2 Auto Scaling based on Number of Request count

Binal Kagathara
5 min readAug 12, 2021

--

What is Auto Scaling ??

AWS Auto Scaling monitors your applications and automatically adjusts capacity to maintain steady, predictable performance at the lowest possible cost. Using AWS Auto Scaling, it’s easy to setup application scaling for multiple resources across multiple services in minutes.

In this tutorial we are going to configure below mentioned task,

Configure ec2 auto-scaling based on the number of request counts. ( If the request counts 1500 continuously coming on my Load Balancer for 10 minutes then it will automatically boot up a new machine and add it into the load balancer).

If we want to do auto-scaling based on the number of request counts, we have to create the auto-scaling group with a target tracking scaling policy.

First of all, we need to create launch configuration:

  1. Go to the EC2 dashboard. In the sidebar select ‘launch template’ and click on ‘Create launch Template’

2. Configure the details like , name , AMI , Instance Type and Key Pair.

3. Click on the Launch Template.

4. We can create ALB by 2 ways: either create target group earlier or else create target group at point of time when alb is created. Here, we firstly Create target group. Go to Target group from left navigation panel.

5. Create target group and give name, protocol. Choose VPC and define health check period as well as path.

6. Register target by clicking on including below and when pop-on comes saying register pending targets only, click on yes.

7. Now, for load balancer, go to left navigation panel and choose load balancer. Choose Application Load Balancer(ALB) and the, create.

8. Give name to ALB and define scheme whether you want internal or internet facing. Add listeners to configuration. Choose VPC and AZs and click on Next Configure Security Settings.

9. Choose Next: Configure Security Groups.

10. Add HTTP & HTTPS in inbound rule of security group as it is internet facing otherwise add vpc cidr as source. Click on Next: Configure routing.

11. Choose existing target group as we have made earlier otherwise you can choose New target group. Define protocol and name. Click on Next: Register Targets to register target EC2 instances.

12. As we have already registered it while creating target group, click on Next: Review and after reviewing, click on Create.

If not existing, choose new target group and register it.

13. From the EC2 dashboard from the sidebar select auto-scaling groups

14. Select ‘Create Auto Scaling group’. Give name and select the launch configuration or the launch template that you have created earlier.

15. Configure the network details like, VPC and Subnets.

16. In the next step, If you want to add a load balancer select ‘Attach to a new load balancer’. Here, we are attaching to distribute load and also, give time for Health check grace period as well as type of health check. Enable Cloudwatch metric if you want.

17. Configure Group size and Scaling policies, Under the ‘Group size’ select the minimum capacity and maximum capacity , this will allow the auto scaling group to scale in range of that. Scroll down and select ‘Target tracking scaling policy’. Give the name, select the metric type and give the target value as ‘1500’. Also, give instance warm-up time period.

18. Add notification via creating SNS topic.

19. Add tags and at last, after reviewing, create it.

20. Increase load on CPU to test auto-scaling. You will see CPU utilization as given below via Cloudwatch metric.

21. Auto-scaling will automatically launch instances according to your capacity configured earlier as well as in accordance with target tracking policies.

22. When CPU load will decrease, it will automatically scale-in the instances. Notification of each steps will be there in your email id you configured via SNS topic. You can see in activity as well.

Bravo!!We are successfully able to do auto scaling based on number of requests.

If you like this then don’t forget to clap!

--

--

Binal Kagathara

DevOps Engineer| AWS Certified Solution Architect - Associate | IT student