Created
August 20, 2014 17:01
-
-
Save tsaavik/3f055abcb16eebcf492a to your computer and use it in GitHub Desktop.
AWS motd tag dumper
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
/etc/update-motd.d/95-aws-tags | |
#!/bin/bash | |
# Print some info from the aws tags | |
# Color codes from http://stackoverflow.com/questions/4332478/read-the-current-text-color-in-a-xterm/4332530#4332530 | |
black=$(tput setaf 0) | |
red=$(tput setaf 1) | |
green=$(tput setaf 2) | |
yellow=$(tput setaf 3) | |
lime_yellow=$(tput setaf 190) | |
powder_blue=$(tput setaf 153) | |
blue=$(tput setaf 4) | |
magenta=$(tput setaf 5) | |
cyan=$(tput setaf 6) | |
white=$(tput setaf 7) | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
#blink=$(tput blink) | |
rev=$(tput smso) | |
underline=$(tput smul) | |
metadata=() | |
while read; do | |
metadata+=("$REPLY") | |
done < <(/usr/bin/ec2metadata --availability-zone --instance-id --instance-type --local-hostname) | |
echo "${bold}Welcome to ${blue}${rev}${metadata[1]}${normal}${white} running on a ${green}${rev}${metadata[2]}${normal}${white} in the ${cyan}${rev}${metadata[0]}${normal}${white} datacenter" | |
echo "${normal}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simpler option, might be more reliable with AWS changes in future, and if you have good tags, even better!
export AWS_ACCESS_KEY_ID=Your ID
export AWS_SECRET_ACCESS_KEY= Your Key
export AWS_DEFAULT_REGION=$(/usr/bin/ec2metadata --availability-zone)
url="http://169.254.169.254/latest/meta-data/instance-id"
instance_id=$(curl --noproxy 169.254.169.254 --fail --silent ${url})
aws ec2 describe-tags --color on --no-paginaete --filters "Name=resource-id,Values=${instance_id}" --output table