Created
April 30, 2019 11:34
-
-
Save jacoor/1088efc66c2bf168c08c290bf69f6969 to your computer and use it in GitHub Desktop.
AWS EC2 user data error handling
This file contains hidden or 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
# error handling | |
# redirect logs so can be found in instance -> actions -> instance settings -> Get System log | |
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
# trap errors. Shutdown restarts machine in an hour and prevents further commands, | |
# so instances won't finish booting and won't report to ECS | |
function my_trap() | |
{ | |
echo "Sorry, there was an error at line $1 $2" && shutdown -h +60 | |
} | |
trap 'my_trap $${LINENO} $$? ' ERR | |
# /error handling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment