Amazon Elastic Compute Cloud (EC2)
EC2 Advanced
EC2 Instance Autoscaling Group
Introduction
In this guide, we explore how EC2 Auto Scaling Groups (ASGs) help maintain application performance and cost efficiency on AWS. You’ll learn the core concepts, scaling policies, and configuration best practices for automatically adjusting EC2 capacity to match real-world demand.
Bakery Analogy for Auto Scaling
To visualize Auto Scaling, imagine a bakery that manages ovens based on customer flow:
- When ovens reach 80% capacity, a new oven turns on.
- When utilization drops below 20%, an oven shuts off.
This model ensures resources dynamically match demand—just like AWS Auto Scaling Groups.
What Is EC2 Auto Scaling?
AWS Auto Scaling Groups automatically add or remove EC2 instances to maintain performance and availability. When incoming traffic spikes, ASGs launch new instances; when demand subsides, they terminate unneeded instances.
Key Features
- Automated Scaling Policies (manual, dynamic, scheduled)
- Auto Healing to replace unhealthy instances
- Seamless integration with Elastic Load Balancing and CloudWatch
Fixed Limit (Manual) Scaling
Specify minimum, desired, and maximum capacity for your ASG. The group:
- Always runs at least the minimum instances.
- Launches up to the desired count.
- Never exceeds the maximum.
Auto Healing
Auto Healing leverages health checks to detect failed instances. When an instance is marked unhealthy, ASG terminates and replaces it to preserve capacity.
Dynamic Scaling Policies
Dynamic scaling adapts in real time to workload fluctuations. ASGs support three policy types:
Scaling Policy Type | Description | Example Metric |
---|---|---|
Target Tracking | Maintain a target metric (e.g., CPU) | CPUUtilization |
Simple Scaling | Triggered by one CloudWatch alarm | S3 ObjectCount |
Step Scaling | Multi-tier adjustments based on thresholds | ≥70% adds 2 instances |
Note
You can monitor default metrics like CPU, network in/out, or Application Load Balancer request count. For custom metrics, publish them to CloudWatch first.
Target Tracking Scaling
Automatically keeps a metric at your target value. For instance, set a 50% average CPU utilization across two instances. If utilization exceeds 50% for five minutes, ASG adds an instance; if it falls below, it removes one.
Simple Scaling
Uses a pair of CloudWatch alarms—one for scale-out and one for scale-in. When an alarm triggers, ASG adjusts capacity by a fixed number or to a specific size.
Step Scaling
Allows tiered responses to metric breaches. Define thresholds and corresponding adjustments (e.g., >60% CPU adds 1 instance, >90% adds 3).
Warning
Ensure your CloudWatch alarms have sufficient evaluation periods to prevent flapping (rapid scale up/down).
Scheduled Scaling
Plan capacity around predictable load patterns. For example, increase desired capacity from 10 a.m. to 8 p.m. and schedule scale-down afterward. Scheduled actions support one-time or recurring cron expressions.
Launch Templates
An Auto Scaling Group requires a launch template defining the AMI, instance type, network settings, security groups, and key pairs. This template ensures consistency across all instances launched by ASG.
For detailed steps, refer to the EC2 Launch Templates documentation.
References
- AWS Auto Scaling Groups: https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html
- Application Load Balancer: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html
- CloudWatch Alarms: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html
- EC2 AMIs: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html
Watch Video
Watch video content
Practice Lab
Practice lab