1

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

Cyril N.
  • 38,875
  • 36
  • 142
  • 243
  • 1
    What kind of termination policy did you set? That should prevent the instance from being stopped – Paolo Jan 24 '22 at 17:22
  • Termination policy prevents the instance from being stopped/terminated. Could you specify how/what termination policy did you set? – Riz Jan 24 '22 at 20:58
  • I did not set any specific termination policy,but upon checking, it's on "`Default`". – Cyril N. Jan 25 '22 at 08:50

2 Answers2

2

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.

Riz
  • 1,131
  • 1
  • 9
  • 12
0

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

Rakesh B E
  • 786
  • 4
  • 5