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
#!/bin/bash | |
set -o errexit # exit on errors | |
set -o nounset # exit on use of uninitialized variable | |
set -o errtrace # inherits trap on ERR in function and subshell | |
trap 'traperror $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]:-})' ERR | |
trap 'trapexit $? $LINENO' EXIT | |
function trapexit() { |
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
#!/bin/bash | |
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}') | |
FQDN=$(aws ec2 describe-tags --region $REGION --filters "Name=resource-id,Values=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" "Name=key,Values=Name" --query Tags[].Value --output text) | |
HOSTNAME=$(echo $FQDN | cut -d. -f1) | |
IPADDRESS=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) | |
if [ -z "$HOSTNAME" ]; then | |
echo "You forgot to set Hostname in Tag Name." | |
exit 0 |