How to setup autoscaling in AWS?

Setup Auto-Scaling in AWS

What is auto-scaling?

Auto scaling is used to scale in and scale out the instances in the cluster as per the autoscaling policies. It will auto scale the machines as per the demand for example, we have one cluster of four instances and we setup the autoscaling on the cluster like it will “scale out” one instance when our CPU utilization is greater than 80% and “scale in” when our CPU utilization is below than 30%. So it will check the scaling policies if it is matched then perform the task which is assigned to the policy.

Prerequisites:-
Ec2 Instances
AMI (image of EC2 instance for launch configuration)
Load Balancer (It is recommended because without load balancer auto scaling is zero)
Launch Configuration
Auto scaling Group

Before this blog I explained about the load balancer , to know about AWS load balancer please click on the link given below:-
https://www.devopscheetah.com/create-loadbalancer-in-aws/ 

So now we start to “Setup of Auto Scaling in AWS“, this is used scale up and down as per the requirement, we set some alarms and define some threshold, when alarm will trigger then it will send us a notification on mail and work as per the circumstances. 

Click on create launch configuration

Auto Scaling in AWS
Auto Scaling in AWS


Now select ami which we created (MY AMIs), because for launch configuration we need to define some basic details like AMI, Instance Type etc.


Define instance type like t2.micro, and after that you will see this image


Now define name

Enable cloud watch detailed and then go to advance details
IP address type = assign a public Ip address to instances


Now click on add storage, if you want to add storage(EBS volume) you can


Now click on security group and select existing one or if you want create another you can


Then click on preview and create launch configuration


Now select existing key pair to access the instance.

Now your launch configuration is ready, Now we will go ahead for auto scaling group.


Click on Auto scaling group then you will see this image


Click on create auto scaling group then you will see this image and select launch configuration which we created recently


Then you will get this image


Define all the details
Group name =
Launch configuration = define the launch configuation
Group Size = define how many instances we want more in current situation (Example our running instances are 2 and we define the value 1, so after this our current VMs are 3).
Network subnet = select subnet


Then you will see this image and select the scaling policy


Then you will see this image


Now, Define the details

define the minimum and maximum size of the group, so define the details as per the project requirements.
Click on “scale the auto scaling group using step or simple scaling policies”, after that click you will get the option of “Add new alarm”


Click on add alarm and define the details


Click on create topic Define the mail id and after that you will get an email to approve the SNS subscription
Average = cpu utilization (as per your metrics which you want to monitor)

 

Now click on create alarm. Same things do for scale down.

 

Create alarm again for it

Click on create alarm.


Now click on next configure Notifications then you will see this image


Click on configure tag define the name


Click on review


click on create auto scaling group

Congratulation, your auto scaling group is ready.
So today we learned about “How to Setup Auto Scaling in AWS

If you need to do testing use stress command and increase the CPU utilization 90% for 10 minutes and when it will meet the autoscaling policy the it will spin up the new instance.

Before this blog I explained about “How to create Load Balancer in AWS” , so if you want to learn about load balancer please click on link given below:-
https://www.devopscheetah.com/create-loadbalancer-in-aws/

Leave a Reply

Your email address will not be published. Required fields are marked *