1

Is it possible to run a powershell script when scaling in servers before the instance is terminated? If so are there any examples of how to achieve this?

Scenario: I am planning on AutoScaling servers based on CPU. I am automatically provisioning them into an Octopus Deploy environment (Continuous Deployment) but before they are terminated I need to unregister the instance with Octopus via a HTTP Post.

Mark Walsh
  • 3,241
  • 1
  • 24
  • 46
  • Not sure I follow. You can execute scripts in octopus either using script console, or you can create a process which executes custom powershell scripts. WHat would you need? – Erti-Chris Eelmaa May 26 '15 at 08:37
  • My specific case is Octopus Deploy specific but really I just need to be able to run *a* script when scaling in. AWS Lifecycle hooks documentation seems fairly thin on the ground in terms of Windows. – Mark Walsh May 26 '15 at 11:43
  • I have the same issue and just end up running an hourly job that checks the Octopus environment for EC2 instances that are no longer available and deletes them from Octopus. That way you do not depend on that powershell script running on your machine's death. – brianfeucht Jun 11 '15 at 17:02
  • I believe Octopus Deploy 3.1 might alleviate your need for a job to be run. – Mark Walsh Jun 15 '15 at 09:37

1 Answers1

1

There are ways to tap into the shutdown event of windows but that might be unreliable depending on how rudely windows shuts off.

This might be useful Executing a batch script on Windows shutdown

I would suggest using CloudWatch Alarms and using AWS SNS to subscribe to the events when the AutoScaling Group decreases in size and that message should have details of the machine that has just been removed.

Community
  • 1
  • 1