【发布时间】:2022-01-14 17:07:52
【问题描述】:
我正在使用 AWS cli,我希望能够查询实例以获取它们的名称和状态。示例:
instance 1, running
instance 2, stopped
我可以通过这个查询获得实例名称和状态
aws ec2 describe-instances --output json --filters Name=tag:Name,Values=*"instance "* --query "Reservations[].Instances[]" | jq ".[] | .Tags, .State.Name"
但是,这给了我一个对象数组和一个值。
[
{
"Key": "Name",
"Value": "instance 1"
},
{
"Key": "VPC",
"Value": "the vpc"
},
{
"Key": "ami_backup",
"Value": "false"
},
...
]
"running"
差不多了。如何将每个对象的值与状态字符串结合起来,以便我可以过滤对象以仅获取 Key==Name 的对象?
我尝试使用map,但找不到有效的语法。
【问题讨论】:
标签: json jq export-to-csv aws-cli