Home > Back-end >  How to always keep one EC2 instance in an auto-scaling group?
How to always keep one EC2 instance in an auto-scaling group?

Time:01-25

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?)

CodePudding user response:

If you want to make sure that "at least one EC2 instance is always available in a given AZ", then you would need to ensure that there are sufficient instances in the Auto Scaling group to cover all configured AZs. For example, if two AZs have been configured for the Auto Scaling group, then set the minimum size of the group to 2. This will ensure that both AZs have instances.

There is also Instance Scale-In Protection that can mark an instance as 'protected', so that it is not terminated. However, this is not necessarily suitable for your situation because the instance would need to be marked whenever it is replaced. It is intended for use in very specific circumstances

Refer the below link for more details. Controlling which Auto Scaling instances terminate during scale in

CodePudding user response:

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.

  •  Tags:  
  • Related