AWS — Auto Scaling

Athira KK
6 min readJul 9, 2023

--

Autoscaling is an advanced feature of AWS which will automatically do resource management based on server load.

📌𝐌𝐚𝐣𝐨𝐫 𝐂𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭𝐬:

🔹EC2 instance — Virtual server exists in ec2 , applications are deployed through this.

🔹Autoscaling group — collection of EC2 instances and policies , ads/removes instances depend on the load.

🔹AMI — Amazon Machine Image — It provides all information required to launch new instances. Multiple instances can be launched from one AMI.

🔹Load Balancer — It is used to increase the capacity and reliability of applications. The main function is to divide traffic among instances.

Now let’s start the hands-on……………………

❎For creating first instance , setup as following , please note that here we are discussing basic settings on Auto Scaling.

❎If you do not have any key pair to login , then create it. Here I’m using the existing one.

From above image , we can see that we have given load balancer name as example-load balancer.

❎Under Advanced Details

❎Launch another instance as same as above, but select the load balancer which we have created above by selecting the existing security group.

❎Now we have 2 instances , and we are going to configure Load Balancer.

❎From left side click on load balancer , as we’re on learning stage , let us select Classic Load Balancer.

❎From above the first protocol (load balancer) will be the front-end and Instance protocol will be our server , which we’re going to configure (eg: if we’re going to configure apache , then port number will be 8080).

❎Load balancer will automatically perform health checks on your EC2 instances and only route traffic to instances that pass the health check. If an instance fails the health check, it is automatically removed from the load balancer.

❎Load Balancer will check the server on port 80 to know the alive status. If more than 2 unsuccessful attempts , then load balancer will not send any further request to the server , but it will keep on checking.

❎Now go to instances and take the public IP of 2 instances and paste it in the browser on different tabs. We can see the difference in the output.

❎Webserver2:

❎Webserver1:

❎Now go to the load balancer and open DNS name in a browser and keep reloading it. We can see the IP address is changing.

❎Now we are going to terminate the 2 instances which we have created above.

Autoscaling should start with an empty load balancer.

❎First create a launch template , for that :

❎From EC2 — click on Launch Templates and then click on create launch template.

❎Provide the launch template name as per your wish , here I gave Webserver.

❎Then we need to provide an AMI , for that to take AMI id from the instance or click on the launch instance and copy the AMI ID from there.

❎Example of AMI ID to be copied — ami-069d73f3235b535bd.

❎Select the existing key pair and security group as load balancer name.

❎Now paste the below into User data coming under Advanced details:

#!/bin/bash

yum install httpd -y

service httpd start

chkconfig httpd on

hostname > /var/www/html/index.html

❎Then click on create launch template.

❎We are going to create auto scaling group , select the template we have created and go to Actions and select create Auto Scaling Group . Please find this from the above image.

❎Select all AZs and subnets from your region, here I’m using the Ohio region.

❎Choose existing load balance as following below steps:

❎And reduce the health check grace period from 300 to 150.

❎In below , we are giving group size and scaling policies :

❎Now we have created an Auto Scaling Group.

❎Now go to Instances and refresh the browser. We can see one instance has been created as we have specified the minimum capacity as one.

❎Please see below to verify the load balancer and newly created instance is syncing:

❎Output of load balancer DNS name:

❎Output of newly created instance private IP:

❎Let us give a CPU load to the first instance and see the new instances are created automatically.

❎Now take the public IP of instance and login to it. I’m using MobaXterm to take the session and run following commands:

❎Then take a duplicate session and give top command.

❎We can see CPU utilization is 100.

❎Now go to the instances dashboard on AWS console , wait for few seconds and watch new instance is being created.

❎Then goto Load Balancers and see the newly created instance is also attached in load balancer:

❎Now go to Load balancer DNS which we have copied into browser and keep reload the page. We can see the private IPs of both instances created .

❎Private IP of second Instance created:

❎Private IP of first Instance created:

🛑The instances will keep on creating, so once you’ve done practicing, go to Autoscaling and delete the auto-scaling group. It will automatically delete the instances, delete the load balancer as well to avoid the costs.

--

--

Athira KK
Athira KK

Written by Athira KK

AWS DevOps Engineer | Calico Big Cats Ambassador | WomenTech Global Ambassador | LinkedIn Top Cloud Computing Voice

Responses (1)