What is Auto Scaling and How Does it Work?

Table of contents
What is Amazon EC2 Auto scaling ?
Amazon EC2 Auto scaling helps you ensure that you have the correct number of Amazon EC2 instances available to handle the load for your application, you create collections of EC2 instances, called Auto scaling groups. you can specify the minimum number of instances in each Auto scaling group, and Amazon EC2 Auto scaling ensure that your group never goes below this size. you can specify the maximum number of instances in each auto scaling group, and Amazon EC2 Auto scaling ensure that your group never goes above this size. if you specify the desired capacity either when you create the group or at any time thereafter, Amazon EC2 Auto scaling ensure that your group has this many instances, if you specify scaling polices, then Amazon EC2 Auto scaling can launch or terminate instances as demand on your application increases or decreases.
In real life, the load on your websites and application can change.
In the cloud, you can create and get rid of servers very quickly.
The goal of an auto scaling group (AGS) is to
Scale out (add EC2 instances) to match an increases load.
Scale out (remove EC2 instances) to match an increases load.
Ensure we have a minimum and a maximum number of EC2.
Automatically resister new instances to a load balancer.
Re-create an EC2 instance in case a previous one is terminated (Ex. : if unhealthy)
ASG are free (you only pay for the underlying EC2 instance)
Auto scaling group attributes :
AMI + instance type
EC2 user data
EBS volumes
Security groups
SSH key pair
IAM roles for your EC2 instance
Network + subnets information
Load balancer information
Min size / Max size / Initial capacity
Auto scaling cloud watch Alarms and scaling :
It is possible to scale an AGS based on cloud watch alarms.
An alarm monitors a metric (such as average CPU, or a custom metric)
Metric such as average CPU are computed for the overall AGS instances.
Based on the alarm.
We can create scale-out policies (increases the number of instance)
We can create scale-in policies (decrease the number of instances)
Prerequisites :
An existing VPC and Subnets.
A Launch Template or Launch Configuration.
Elastic Load Balancer (ELB).
An Amazon Machine Image (AMI) to launch EC2 instances.
Create Auto Scaling Group in AWS Console :
Step 1 : Create a Launch Template
Go to EC2 Dashboard.
In the left menu, click Launch Templates Create launch template.
Name
launch template - create launch template
template name
template description
create image of EC2
my AMI
owned by me or AWS machine template
key pair create launch template
After that
Launch template -launch template name -next
Network - VPC - default - Availability zones and subnets - select zone - balanced best effort -next.
Load balancing - attach to an existing load balancer attach to the an existing load balancer
choose from your load balancer targets groups.
select target groups
health checks - turn on - next
scaling - automatic scaling - target tracking - scaling policy -next
add notification - optional - next
add tags - next
create auto scaling group.
Conclusion:
Amazon EC2 Auto Scaling is a powerful tool that ensures your application has the right amount of resources to handle varying loads efficiently. By creating Auto Scaling Groups, you can automatically adjust the number of EC2 instances based on demand, ensuring optimal performance and cost-effectiveness. With features like scaling policies, integration with CloudWatch alarms, and seamless load balancer registration, EC2 Auto Scaling provides a robust solution for maintaining application availability and reliability. Whether you're dealing with fluctuating traffic or planning for growth, EC2 Auto Scaling helps you manage your infrastructure dynamically and efficiently.
Subscribe to my newsletter
Read articles from Tambadkar Rohit Yashwant directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Tambadkar Rohit Yashwant
Tambadkar Rohit Yashwant
Learning DevOps Engineer passionate about cloud computing, containerization, and automation. Currently exploring Docker, AWS, and CI/CD pipelines to build scalable and efficient workflows. Documenting my learning journey in blog. stay tuned with me for learning.