Gaspar
Gaspar

Reputation: 165

How to know if my instance will be terminated in ec2?

I have a autoscalling in AWS, that basically do:

  1. Run a python process script.py
  2. This script get messages from sqs queue to process

My autoscalling is configured to start/terminate instance based on # of avaliables messages in queue. But sometimes when i processing something in machines and my # of messages, my autoscaling trigger to terminate instances, so i end losting message in the middle of processing.

I starting trying to handler signals but does not seem to be working.

My main goal is:

Is there anyway to archive this? I'm not using load balancing because i manually get the messages from queue.

Upvotes: 2

Views: 338

Answers (1)

varnit
varnit

Reputation: 1897

you can use AWS autoscaling lifecycle hooks, they will put your ec2 instance in wait state before terminating it and deliver a message to SNS or cloudwatch that your instance is ready to terminate you can finish your already processed message in the mean time, i found an interesting blog post explaining the use case similar to yours .

AWS autoscaling lifecycle hooks

Upvotes: 4

Related Questions