Skip to content

Instantly share code, notes, and snippets.

@tfolbrecht
Last active January 27, 2020 22:39
Show Gist options
  • Select an option

  • Save tfolbrecht/fd84627113ebf129cc90520410484cde to your computer and use it in GitHub Desktop.

Select an option

Save tfolbrecht/fd84627113ebf129cc90520410484cde to your computer and use it in GitHub Desktop.
Self Terminate EC2
#!/bin/bash
# *WARNING* This is a fragile solution, if the bash script fails, hangs, etc, the shutdown won't execute.
# Set am asynchronous kill job above the execution of this script with a sensible timeout
# example bash ec2seppuku.sh & sleep 60 && shutdown -h now
# Also set up aws logging, and clean up your aws env periodically just in case
# ¯\_(ツ)_/¯
# launch with --instance-initiated-shutdown-behavior terminate so it cleans up
if command; then
echo ""
else
echo "Some failure occured"
fi
shutdown -h now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment