You can use AWS EC2 metadata service and AWS CLI to get EC2 instance tags from within the AWS EC2 instance.
1 2 3 4 5 6 7 8 9 10 |
## Get EC2 instance id from metadata INSTANCE_ID=`wget -qO- http://instance-data/latest/meta-data/instance-id` ## Get EC2 instance region from metadata REGION=`wget -qO- http://instance-data/latest/meta-data/placement/availability-zone | sed 's/.$//'` ## Get EC2 instance tags using AWS CLI aws ec2 describe-tags \ --region $REGION \ --filter "Name=resource-id,Values=$INSTANCE_ID" |