0

I want to execute some code on the instance before it is terminated. I could set a lifecycle hook to a lambda, which in turn ssh's into the instance and executes said code. But I would really like it if it is was possible to sed the notification to the instance being terminated.

I read somewhere this is possible, but i can't figure out a way. Anyone knows?

Thanks a lot, guys!

David Villasmil
  • 395
  • 2
  • 19
  • To get better answers, you should describe your operating system and explain exactly what you want to do. Otherwise, the best someone can do is point you at the [docs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html#preparing-for-notification). – kdgregory Dec 01 '18 at 11:25
  • That said, I strongly caution against relying on a shutdown notification. There are many reasons that an instance can shut down, and you'll only be notified on scale-in. – kdgregory Dec 01 '18 at 11:26
  • @kdgregory That's exactly what i'm talking about (as per the question title) AWS ASG (scale in). I doubt what operating system i'm using is relevant to this question, is it? In any case, it's debian 8. – David Villasmil Dec 01 '18 at 11:38
  • My point is that whatever you want to do on the instance during scale-in is not going to happen if the instance is terminated for any other reason. As for the OS, there are no doubt different capabilities for Windows versus Linux. – kdgregory Dec 01 '18 at 12:34
  • @kdgregory I understand. But I’m specifically talking about Scale in termination. :) – David Villasmil Dec 01 '18 at 13:37
  • Well, in that case, I don't know of any undocumented notification mechanism, and wouldn't expect one to exist. I would probably use SNS integration with my application, rather than SSH from a Lambda, but without knowing what you're trying to accomplish, I can't really answer that either. – kdgregory Dec 01 '18 at 14:04
  • @kdgregory when the ASG terminates an instance, it simply shuts down the instance, without going through the shutdown process, meaning it doesn’t do a graceful shutdown. In when my instance starts up, it registers on my server, and before shutting down, it should unregister, and this is done via systemd. I’m trying to think of a way of accomplishing this. – David Villasmil Dec 01 '18 at 14:13
  • So, if I understand correctly, you have two types of server: a single "control" server and multiple "worker" servers managed by the ASG? In that case, is there a reason that you wouldn't notify the "control" server of the ASG events, _including_ registering the server when it starts up? Or is there additional information that the "worker" server sends to the "control" server? – kdgregory Dec 03 '18 at 11:10
  • @kdgregory thanks buddy, but I figured out a better way of not needing a lambda :) thanks anyway! – David Villasmil Dec 06 '18 at 20:40

0 Answers0