Skip to content

Instantly share code, notes, and snippets.

@tfentonz
Last active June 22, 2021 22:10
Show Gist options
  • Save tfentonz/1ce67e2375f9d6e630c0c0fbe308f81a to your computer and use it in GitHub Desktop.
Save tfentonz/1ce67e2375f9d6e630c0c0fbe308f81a to your computer and use it in GitHub Desktop.
Get EC2 Name tag value
#!/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