AWS Auto Scaling adds or removes the EC2 instances automatically based on a pre-configured condition. When a new EC2 instance is launched automatically it will be added to the Auto Scaling group. Auto Scaling allows the user to add a policy to decide on the termination of an instance. Before Auto Scaling terminates the EC2 instance, it first checks the availability zones. It will find the availability zone with the highest number of instances and delete the instance from there. If all the availability zones have the same number of instances, Auto Scaling selects any random zone. Once the availability zone is defined, Auto Scaling uses the termination policy to identify the instance to be deleted.
By default, Auto Scaling will delete the oldest instance from the selected availability zone. If more than one instance was launched simultaneously based on the scaling policy, Auto Scaling will take the instance that is closest to next instance hour. The above mentioned policy can result in cost savings. If more than one instance has the same time, Auto Scaling selects any random instance.
The present guide demonstrates how to configure and test the above mentioned termination policy for Auto Scaling. Since AWS does not provide the management console for Auto Scaling, all the tasks would be performed by CLI.