Last active
June 22, 2021 22:10
-
-
Save tfentonz/1ce67e2375f9d6e630c0c0fbe308f81a to your computer and use it in GitHub Desktop.
Get EC2 Name tag value
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 | |
instance_id=$(curl -s 169.254.169.254/latest/meta-data/instance-id) | |
name=$(aws ec2 describe-tags \ | |
--filters \ | |
"Name=resource-type,Values=instance" \ | |
"Name=resource-id,Values=$instance_id" \ | |
"Name=key,Values=Name" \ | |
--query "Tags[].Value" \ | |
--output text) | |
echo "$name" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment