David Villasmil
David Villasmil

Reputation: 415

Auto Scaling group lifecycle hook periodic notification

So I have this scenario where an Amazon EC2 instance in an Auto Scaling group will be terminated. My problem is that I don’t want it terminated until it has finished whatever it’s doing.

If I hook up a lambda, the lambda would check a metric, if this metric is > 0 then it needs to wait 60 seconds.

I have this done already, the problem is it may take more than the Max timeout for lambdas of 15 minutes, to finish the jobs it’s processing.

If I read correctly, the lifecycle notification is only sent once, so this lambda won’t work for me.

Is there any other way of doing this?

Upvotes: 0

Views: 415

Answers (2)

you can reinvoke the lambda function in 5 minutes so that it continues checking

Upvotes: 0

gp42
gp42

Reputation: 545

Here is how I would try to approach this problem (this is a needs a POC, the answer is theoretical):

  1. Create an Auto Scaling Group
  2. Put a lifecycle hook on this ASG like described here, sending notification to Amazon SNS
  3. Create a launch script for instances which will do the following
    • subscribe to SNS on instance launch and start SNS listener script
    • SNS listener will wait for instance termination message, do whatever necessary to wait until instance is ready to terminate, including sending heartbeats if termination needs more than 1h and completing lifecycle hook (described here). This should also handle unsubscription from SNS.

Upvotes: 1

Related Questions