I am in need of knowing when an instance is supposed to be shutdown by the autoscale, as I want the instances to register themselves and deregister themselves from a given service.
I know that the autoscale can start/stop any instance any time so I need the instances to be notified of when are they going to be shutdown.
Is there anyway of achieving this behaviour?
I haven't found anyway to do this whole process through the CLI as it seems that Amazon hasn't added the SQS service to its api tools for linux. However, yes it is possible to do and its really not too difficult.
Click the SNS tab
Using the command line tools or some other interface run the command below. After running this command all notifications will be sent using the defined protocol.
as-put-notification-configuration <auto-scaling-group> -t <topic-arn> -n autoscaling:EC2_INSTANCE_LAUNCH,autoscaling:EC2_INSTANCE_TERMINATE
I recommend sending them to SQS first then to your application. Its a little bit safer to have the messages stored in a queue and read from them. The only problem with SQS is its a little more complicated to get going, but there's plenty of documentation about SQS and a good API in almost any language you're using.