Amazon EC2 Auto Scaling
Auto add/remove servers
Automatically increases or decreases the number of EC2 instances based on load or a schedule, and replaces unhealthy instances.
- Cost$ Low
- Difficulty●●●●●
- Costs money when idle?No
- Managed by AWS
- In examsCLF · SAA · SOA
Think of it asLike a restaurant manager calling in extra staff at peak hours and sending some home when it's quiet.
Where does EC2 Auto Scaling fit?
Calls EC2 Auto Scaling
EC2 Auto Scaling calls
A real example, step by step
- A ticketing website usually needs 2 EC2 instances, but when concert tickets go on sale at 8 p.m., traffic jumps tenfold.
- You create an Auto Scaling group: minimum 2, maximum 20 instances, spread across 3 AZs, with a policy that keeps average CPU around 50%.
- When CPU goes above 50%, the group launches more instances from the launch template and registers them with the load balancer; customers never see a slowdown.
- After the sale, CPU drops and the group terminates instances back down to 2, so you only pay for extra capacity while you need it.
- If an instance fails, health checks catch it and the group replaces it — nobody has to stay up at night.
When to use it
✓ Use it when
Load changes by the hour and you need automatic recovery when a server dies.
✗ Avoid it when
The app can only run on exactly one server (has local state).
Common uses
- Web tier that scales out/in based on CPU or request count
- Keep a fixed N servers and automatically replace failed ones (self-healing)
- Scheduled scaling, e.g. business hours
EC2 Auto Scaling, ELB or Lambda?
| What it does | Adds, removes and replaces EC2 instances | Spreads requests across running instances | Runs more copies of a function automatically |
|---|---|---|---|
| You configure | Min/max size and scaling policies | Listeners, target groups, health checks | Almost nothing (there is a concurrency limit) |
| Cost | Free; you pay for the EC2 instances | Hourly plus capacity used | Requests and run time |
| Usually paired with | A load balancer and CloudWatch | An Auto Scaling group | API Gateway, SQS, S3 |
What does it cost?
- Pricing model: Free. You only pay for the EC2 instances the group launches and the associated CloudWatch alarms.
- Free tier: Auto Scaling itself is free.
Setting the maximum too high or scaling in too slowly leaves extra servers running; wrong health checks cause servers to be replaced over and over.
“Survive the loss of an AZ” → an Auto Scaling group across multiple AZs with an ALB. Known peak times → scheduled scaling; keep one metric steady → target tracking. Instances must be stateless: move sessions to ElastiCache or DynamoDB.
Try real exam questions
1In an experiment, if the minimum size for an Auto Scaling group is 1 instance, which of the following statements holds true when you terminate the running instance?
- AAuto Scaling must launch a new instance to replace it.
- BAuto Scaling will raise an alarm and send a notification to the user for action.
- CAuto Scaling must configure the schedule activity that terminates the instance after 5 days.
- DAuto Scaling will terminate the experiment.
Show answer
Correct answer: A
Auto Scaling always keeps at least the minimum number of instances. If an instance is terminated, the group launches a replacement.
2You need to pass a custom script to new Amazon Linux instances created in your Auto Scaling group. Which feature allows you to accomplish this?
- AUser data.
- BEC2Config service.
- CIAM roles.
- DAWS Config.
Show answer
Correct answer: A
User data is a script that runs when an instance first boots, defined in the Auto Scaling group's launch template. EC2Config is only for older Windows; IAM roles and AWS Config don't run scripts.
Frequently asked questions
What kinds of scaling policies are there?
Target tracking keeps a metric near a target value (for example 50% CPU). Step scaling adds or removes capacity in steps based on alarm thresholds. Scheduled scaling follows a known timetable. Predictive scaling forecasts load from history and launches capacity ahead of time.
Does EC2 Auto Scaling cost anything?
Auto Scaling itself is free. You pay only for the EC2 instances and other resources the group launches, plus the CloudWatch alarms used to trigger scaling.
What do AWS exams ask about Auto Scaling?
Spreading instances across multiple AZs to survive an AZ failure, combining ALB health checks so failed instances are replaced automatically, choosing the right policy (target tracking or scheduled) for a scenario, and launch templates as the place where the instance configuration is defined.