Posted On: Jul 29, 2021

Amazon EC2 Auto Scaling now lets you control which instances to terminate during a scale-in event 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 which instances Auto Scaling should terminate from a list of eligible instances. During a scale-in event, Auto Scaling will call the Lambda function, providing it with the list of instance eligible for termination based on your Auto Scaling group’s configuration. Auto Scaling will then only terminate instances that your Lambda function indicates are safe for termination.

This feature is available through the AWS SDKs, and the AWS Command Line Interface (CLI). AWS Management Console support for this feature is coming soon. Amazon EC2 Auto Scaling is available in all public AWS Regions and AWS GovCloud (US) Regions. To learn more about this feature, visit this AWS documentation.