[英]Retrieving exact tag value from aws ec2 instances
I'm using the below command to get the AWS EC2 instance tag value for the tag name called 'Name', but the problem is that I also have a tag called 'Cluster Name' so the code below outputs the tag values for both 'Name' and 'Cluster Name' tags. 我正在使用以下命令来获取名为“ Name”的标签名称的AWS EC2实例标签值,但是问题是我也有一个名为“ Cluster Name”的标签,因此下面的代码输出了两个“名称”和“群集名称”标签。
How can I make it so that I only retrieve the tag value for 'Name' tag? 如何做到这一点,以便仅检索“名称”标签的标签值?
aws ec2 describe-tags --region us-east-1 --filters "Name=resource-id,Values=i-01159fca884xxxxxx" | grep -2 Name | grep Value | tr -d ' ' | cut -f2 -d: | tr -d '"' | tr -d ','
This works on a Mac (quotation formatting might need to change for Windows):v 这在Mac上有效(对于Windows,可能需要更改报价格式):v
aws ec2 describe-instances --filter Name=instance-id,Values=i-xxx --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value' --output text
Here's a very useful reference for understanding how to use --query
: JMESPath Tutorial 这是了解如何使用
--query
的非常有用的参考: JMESPath教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.