Sure! Here’s a clean version of the Auto Scaling Group (ASG) termination policies explanation without any icons:
Default Termination Policy
If you don’t specify a termination policy, AWS uses the default behavior:
- Select the Availability Zone (AZ) with the most instances.
- From that AZ, select the instance with the oldest launch configuration or launch template.
- If multiple instances qualify, pick the one closest to the next billing hour.
- If still multiple, select one at random.
Custom Termination Policies
You can define a list of termination policies, and AWS will evaluate them in the order you provide. Here are the available policies:
Policy | Description |
---|---|
OldestInstance | Terminates the instance that has been running the longest. |
NewestInstance | Terminates the instance that was most recently launched. |
OldestLaunchConfiguration | Terminates instances launched using the oldest launch configuration. |
OldestLaunchTemplate | Terminates instances launched using the oldest launch template. |
ClosestToNextInstanceHour | Terminates the instance that is closest to the next billing hour. |
AllocationStrategy | Applies when using mixed instance types with Spot and On-Demand. Optimizes based on price or capacity. |
Default | Uses the built-in default logic. |
Example (using AWS CLI)
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name my-asg \
--termination-policies "OldestInstance" "Default"
Common Use Cases
- For rolling updates, use
OldestLaunchTemplate
to phase out older versions. - For cost efficiency, use
ClosestToNextInstanceHour
(more relevant for older billing models). - For Spot instance strategies, use
AllocationStrategy
. - To maintain newer instances and remove older ones, use
OldestInstance
.
Let me know if you’d like an example using Terraform or how to set it in the AWS Console.