【发布时间】:2020-11-07 06:13:34
【问题描述】:
我正在尝试解析来自 AWS CLI 的 JSON 输出。我正在寻找的是下面带有特定标签的安全组名称。两个有效的命令是
$aws ec2 describe-security-groups | jq -r '.SecurityGroups[].GroupName'
default
mysqlsg
apachesg
default
然后我跑
$ aws ec2 describe-security-groups | jq -r '.SecurityGroups[].Tags[]|select(.Key == "Service")'
{
"Key": "Service",
"Value": "default"
}
{
"Key": "Service",
"Value": "MySQL"
}
{
"Key": "Service",
"Value": "Apache"
}
{
"Key": "Service",
"Value": "default"
}
我希望每个组的下方都有服务标签,所以我尝试了这个,但没有成功。
$ aws ec2 describe-security-groups | jq -r '.SecurityGroups[].GroupName,.SecurityGroups[].Tags[]|select(.Key == "Service")'
jq: error (at <stdin>:225): Cannot index string with string "Key"
【问题讨论】:
-
“我希望每个组都有服务标签”是什么意思">
-
每个安全组都有 Key Service 的标签。我想显示组名称以及具有密钥服务的标签及其下方的值。
标签: amazon-web-services jq aws-cli