How do I resolve the error "The managed termination protection setting for the capacity provider is invalid" in Amazon ECS?

Last updated: 2021-01-28

When I try to create a cluster capacity provider in Amazon Elastic Container Service (Amazon ECS), I get the following error: "The managed termination protection setting for the capacity provider is invalid. To enable managed termination protection for a capacity provider, the Auto Scaling group must have instance protection from scale in enabled."

How can I resolve this error?

Resolution

To resolve the error, enable scale-in protection on your Auto Scaling group. You can enable scale-in protection using either the Amazon Elastic Compute Cloud (Amazon EC2) console or the AWS Command Line Interface (AWS CLI).

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.

Using the Amazon EC2 console

1.    Open the Amazon EC2 console, and then choose Auto Scaling Groups from the navigation pane.

2.    Select your Auto Scaling group. From the Details tab, scroll down to Advanced configurations, and then choose Edit.

3.    Under Instance scale-in protection, select Enable instance scale-in protection.

4.    Choose Update.

Using the AWS CLI

To enable scale-in protection for the Auto Scaling group using the AWS CLI, run the following command:

aws autoscaling update-auto-scaling-group \
    --region RegionID \
    --auto-scaling-group-name yourASGName \
    --new-instances-protected-from-scale-in

Note: Replace RegionID with your AWS Region. Replace yourASGName with the name of your Auto Scaling group.

Troubleshooting

If you still receive the error, then some of your existing instances launched by the Auto Scaling group might not have scale-in protection.

To apply scale-in protection to the remaining instances using either the Amazon EC2 console or the AWS CLI, follow these steps:

Using the Amazon EC2 console

1.    Open the Amazon EC2 console, and then choose Auto Scaling Groups from the navigation pane.

2.    Select your Auto Scaling group, and then choose the Instances tab.

3.    From the Instance ID column, select the instances to apply scale-in protection to.

4.    On the Instance management tab, choose Actions, Set scale-in protection.

5.    Create a capacity provider in Amazon ECS.

Using the AWS CLI

To list instances from your Auto Scaling group that don't have scale-in protection enabled, run the following AWS CLI command using the query feature:

aws autoscaling describe-auto-scaling-groups \
    --region RegionID \
    --auto-scaling-group-names yourASGName \
    --query 'AutoScalingGroups[].Instances[?ProtectedFromScaleIn==`true`].{Id:InstanceId}' \
    --output text

Note: Replace RegionID with your AWS Region. Replace yourASGName with the name of your Auto Scaling group.

Then, follow these steps to enable scale-in protection for the specified instances in your Auto Scaling group:

1.    Run the following command:

aws autoscaling set-instance-protection \
    --region RegionID \
    --instance-ids yourInstanceID \
    --auto-scaling-group-name yourASGName \
    --protected-from-scale-in
Note: Replace RegionID with your AWS Region. Replace yourInstanceID with your instance ID. Replace yourASGName with the name of your Auto Scaling group.

2.    Create a capacity provider in Amazon ECS.


Did this article help?


Do you need billing or technical support?