【发布时间】:2020-05-11 14:57:05
【问题描述】:
我正在尝试使用 jq 获取 AWS EC2 实例的 Name 标签的值。
aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | .Tags[] | select (.Key == "Name")'
但我收到此错误:
jq: error: Name/0 is not defined at <top-level>, line 1:
.Reservations[].Instances[] | .Tags[] | select (.Key == Name)
jq: 1 compile error
这是我要处理的 json:
{
"Reservations": [{
"Instances": [{
"AmiLaunchIndex": 0,
"ImageId": "ami-00c3c949f325a4149",
"InstanceId": "i-0c17052ee1c7113e5",
"Architecture": "x86_64",
"Tags": [{
"Key": "Name",
"Value": "bastion001"
},
{
"Key": "environment",
"Value": "stg-us-east"
}
]
}]
}]
}
如何从 EC2 实例中获取 Name 标签的值?
【问题讨论】:
-
这是一个Try it online!,带有您的过滤器和 json。一开始看起来还可以。您可以通过添加
| .Value来获取名称。 peak 的建议是最好的,如果你看到像你这样的错误。 -
好棒!谢谢你,我会试试的。
标签: amazon-web-services amazon-ec2 jq