I have auto scaling group in EC2 and I want to detect the state of the instance when it is getting terminated, so that I could start exporting log files before it will be terminated.
I know a way to do this is use autoscaling lifecycle hooks but from my understanding I would have to use external monitor which would then have to ssh into instance and do the export of log files. Ideally I would like to find a way on how to detect state of instance from inside (when the auto scaling group sends command to terminate it) so it would do the export on its own without communicating with any other instances. Anyone would know if its possible to do this, if so where could I begin?