Scale-In Protection and Termination
What you'll learn: How to safeguard specific instances from being terminated when your Auto Scaling group scales in during periods of low traffic.
When traffic decreases, Auto Scaling automatically removes instances to save costs—this is called scaling in. But sometimes you want to protect certain instances from termination, even when capacity needs to decrease.
Why Protect Instances?
Imagine you're running a web application where some instances handle background processing jobs that take hours to complete. If Auto Scaling terminates these instances mid-job, you lose work. Scale-in protection lets you flag specific instances as "do not terminate" until you're ready.
How Scale-In Protection Works
When you enable scale-in protection on an instance:
- Auto Scaling will skip over it when choosing which instances to terminate
- The instance remains part of the group and continues receiving traffic
- You must manually remove protection when the instance is ready to be terminated
- Protection stays active until you explicitly disable it
Termination Policies
When scaling in without protection, Auto Scaling uses termination policies to decide which instances go first:
- Default: Balances across availability zones, then terminates oldest launch configuration
- OldestInstance: Removes the oldest instances first
- NewestInstance: Removes the newest instances first
- ClosestToNextInstanceHour: Minimizes cost by terminating instances near their billing hour
You can set these policies at the Auto Scaling group level to control the default behavior for all unprotected instances.
Real-World Pattern
Use scale-in protection for stateful workloads, database replicas, or instances processing long-running tasks. Combine it with health checks to ensure protected instances remain healthy while handling their critical work.
Key Takeaway: Scale-in protection prevents Auto Scaling from terminating specific instances during scale-in events, giving you control over which instances stay running during traffic decreases.