Search code examples
amazon-web-servicesamazon-ec2aws-lambdaautoscalingaws-auto-scaling

AWS autoscaling detached instance terminated


No Code here.

I am building solution based on EC2 using AutoScaling.

I have created the solution where instance will get detached from AutoScaling group before they are stopped and they will be added back to AutoScaling group when in use. Now what if the instance that I have deteched from AutoScaling has terminated, now I am left with nothing to attach to AutoScaling ( that particular instance id does not exist anymore).

How to handle this , if instance has terminated then at time of attachment AutoScaling should know that Instance does not exist anymore and create a new instance. From here i am planning to create a event bridge which will take Instance-Id of new instance and update it SSM.


Solution

  • I think you might want to use standby instead of detaching/attaching. Any time you have an instance exit standby, the desired will get incremented by 1. No healthchecks are happening on the instance while its in standby, so if the instance got terminated while in standby the ASG wouldn't know about it until you remove the instance from standby.

    Since the desired has already been increased at that point, a new instance would be launched to replace the old one as part of a healthcheck replacement