Change the termination policy for an Auto Scaling group - Amazon EC2 Auto Scaling
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Change the termination policy for an Auto Scaling group

To change the termination policy for your Auto Scaling group, use one of the following methods.

Console

You can't change the termination policy when you initially create an Auto Scaling group in the Amazon EC2 Auto Scaling console. The default termination policy is used automatically. After your Auto Scaling group has been created, you can replace the default policy with a different termination policy or multiple termination policies listed in the order in which they should apply.

To change the termination policy for an Auto Scaling group
  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/, and choose Auto Scaling Groups from the navigation pane.

  2. Select the check box next to the Auto Scaling group.

    A split pane opens up in the bottom of the page.

  3. On the Details tab, choose Advanced configurations, Edit.

  4. For Termination policies, choose one or more termination policies. If you choose multiple policies, put them in the order that you want them evaluated in.

    You can optionally choose Custom termination policy and then choose a Lambda function that meets your needs. If you have created versions and aliases for your Lambda function, you can choose a version or alias from the Version/Alias drop-down. To use the unpublished version of your Lambda function, keep Version/Alias set to its default. For more information, see Create a custom termination policy with Lambda.

    Note

    When using multiple policies, their order must be set correctly:

    • If you use the Default policy, it must be the last policy in the list.

    • If you use a Custom termination policy, it must be the first policy in the list.

  5. Choose Update.

Amazon CLI

The default termination policy is used automatically unless a different policy is specified.

To change the termination policy for an Auto Scaling group

Use one of the following commands:

You can use termination policies individually, or combine them into a list of policies. For example, use the following command to update an Auto Scaling group to use the OldestLaunchConfiguration policy first and then use the ClosestToNextInstanceHour policy.

aws autoscaling update-auto-scaling-group --auto-scaling-group-name my-asg --termination-policies "OldestLaunchConfiguration" "ClosestToNextInstanceHour"

If you use the Default termination policy, make it the last one in the list of termination policies. For example, --termination-policies "OldestLaunchConfiguration" "Default".

To use a custom termination policy, you must first create your termination policy using Amazon Lambda. To specify the Lambda function to use as your termination policy, make it the first one in the list of termination policies. For example, --termination-policies "arn:aws-cn:lambda:us-west-2:123456789012:function:HelloFunction:prod" "OldestLaunchConfiguration". For more information, see Create a custom termination policy with Lambda.