-
-
Save joshjdevl/26ddf5f5e8d9e495c87b to your computer and use it in GitHub Desktop.
ubuntu ec2 bash prompt instance tag name
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
# these make the ec2 commands just work | |
export AWS_ACCESS_KEY=[AWS access key] | |
export AWS_SECRET_KEY=[AWS secret] | |
# fetch the instance id | |
export INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id) | |
#grep out the tag you're looking for, in this case "Name" | |
export APP_TAG=$(ec2dtag --region us-west-2 --filter "key=Name" --filter "resource-type=instance" --filter "resource-id=$INSTANCE_ID" | grep -oE "Name\\W+(.+)$" | grep -oE "\\W.+$") | |
#trim beginning and leading whitespace | |
export APP_TAG=$(echo $APP_TAG | sed -e 's/^ *//' -e 's/ *$//') | |
#put it into the prompt | |
export PS1="\u@$APP_TAG:\w>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment