I have a python script which removed a AWS Ec2 instance from Zabbix monitoring.
I need to have this script run prior to the instance terminating on a auto-scale scale in event.
I have tried placing the script in /etc/init.d and ln -s to /etc/rc0.d
I have also tried chkconfig 0 1 99 and
chkconfig --add script.py --level 0
None of the above methods cause the script to execute when entering runlevel 0
I have created a auto-scale life cycle hook which waits 90 seconds in order to give the script time to execute.
I then created the following bash script which is polled by cron every minute waiting for the Terminating:Wait signal
This also does not work. Nothing executes.
#!/bin/bash INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id
aws autoscaling describe-auto-scaling-inst
ances --instance-ids $INSTANCE_ID | grep -q 'Terminating:Wait'
if [ $? -eq 0 ]; then
aws autoscaling complete-lifecycle-action --lifecycle-hook-name Zabbix-shutdown-wait --auto-scaling-group-name 5sight-prod --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID
So my question is, HOW can I get a aws Linux instance to execute a python script on a auto_scale Termination event.