Posted On: Jul 29, 2021
Amazon EC2 Auto Scaling now lets you control which instances to terminate on scale-in by allowing you to provide a custom function that selects which instances to terminate. Previously, you could use one of the predefined termination policies to determine which instances Auto Scaling would terminate. (For example, the OldestLaunchTemplate termination policy would terminate instances in order of their launch template age, oldest first.) Now, you can provide a custom Lambda function that indicates which instances are safe to terminate on scale-in. This feature is useful for stateful applications where you want to control which instances Auto Scaling terminates so that your application is not disrupted on scale-in.
To use this feature, you need to create a Lambda function that will choose instances Auto Scaling should terminate. During a scale-in event, Auto Scaling will call the Lambda function, providing it with a list of instances eligible for termination and a recommendation of how many to terminate in each AZ based on your Auto Scaling group configuration. Auto Scaling will only terminate instances that your Lambda function indicates are safe for termination. You can choose to terminate more or less instances per AZ than Auto Scaling recommends, as long as you don't terminate more instances than the scale-in requires. This way you have control over how to distribute and pace your terminations based on your application needs.
Amazon EC2 Auto Scaling is available in Amazon Web Services China (Beijing) region, operated by Sinnet and Amazon Web Services China (Ningxia) region, operated by NWCD. To learn more about this feature, visit this documentation.