Query EC2 tags from within instance

前端 未结 14 1738
暗喜
暗喜 2020-12-02 05:57

Amazon recently added the wonderful feature of tagging EC2 instances with key-value pairs to make management of large numbers of VMs a bit easier.

Is there some way

14条回答
  •  时光取名叫无心
    2020-12-02 06:50

    Jq + ec2metadata makes it a little nicer. I'm using cf and have access to the region. Otherwise you can grab it in bash.

    aws ec2 describe-tags --region $REGION \
    --filters "Name=resource-id,Values=`ec2metadata --instance-id`" | jq --raw-output \
    '.Tags[] | select(.Key=="TAG_NAME") | .Value'
    

    No jq.

    aws ec2 describe-tags --region us-west-2 \
    --filters "Name=resource-id,Values=`ec2-metadata --instance-id | cut -d " " -f 2`" \
    --query 'Tags[?Key==`Name`].Value' \
    --output text
    

提交回复
热议问题