Search code examples
amazon-web-servicesamazon-ec2autoscalingaws-auto-scaling

How to always keep one EC2 instance in an auto-scaling group?


I have an auto scaling group at AWS with a few instances. I'd like to define one to be the primary one, where I'll also configure custom scripts to be run on it.

I thought I would enable the "termination protection" for this EC2 instance but it seems that this did not avoid it to be deleted by the Auto scaling group a few moments later.

Is there a way I can have an EC2 instance that is affected to the Auto-scaling group to always stay on ?

(Note: I want it to be accessible via the Load balancer, but I can't detach it from the auto scaling group because the CodeDeploy systeme I have implemented won't work with it?)


Solution

  • I am guessing you have put Instance scale-in protection from autoscaling group -> Advanced configurations. This only put scale-in protection for new instances and not on the instances already inservice. If you want to put scale-in protection on a specific instance, you need to do Instance Management -> actions -> Set scale-in protection. This way your specific instance will not be terminated, even if you set Desired capacity to 0.