Created
May 8, 2017 16:37
-
-
Save sysboss/a748351ce2bd6d2a3fad029aad2b88b5 to your computer and use it in GitHub Desktop.
Handling AWS Spot Instance Termination Notices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# AWS Instance Termination Notice Handler | |
# Based on: https://blog.fugue.co/2015-01-06-spot-termination-notices.html | |
while true; do | |
# get meta-data HTTP headers | |
HEADER=$(curl -Is http://169.254.169.254/latest/meta-data/spot/termination-time) | |
# HTTP 404 - not marked for termination | |
if [ -z $(echo $HEADER | head -1 | grep 404 | cut -d \ -f 2) ]; then | |
echo "Running shutdown hook." | |
# Call your shutdown script here. | |
break | |
else | |
# Spot instance not yet marked for termination. | |
echo "Spot instance not yet marked for termination." | |
sleep 5 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment