下記セキュリティグループがあり、
$ aws ec2 --profile xxx describe-security-groups --group-ids sg-xxx { "SecurityGroups": [ { "Description": "xxx-sg", "GroupName": "xxx-sg", "IpPermissions": [ { "FromPort": 80, "IpProtocol": "tcp", "IpRanges": [], "Ipv6Ranges": [], "PrefixListIds": [], "ToPort": 80, "UserIdGroupPairs": [ { "GroupId": "sg-xxx", "UserId": "xxx" } ] }, { "FromPort": 22, "IpProtocol": "tcp", "IpRanges": [ { "CidrIp": "0.0.0.0/0" } ], "Ipv6Ranges": [], "PrefixListIds": [], "ToPort": 22, "UserIdGroupPairs": [] } ], "OwnerId": "xxx", "GroupId": "sg-xxx", "IpPermissionsEgress": [ { "IpProtocol": "-1", "IpRanges": [ { "CidrIp": "0.0.0.0/0" } ], "Ipv6Ranges": [], "PrefixListIds": [], "UserIdGroupPairs": [] } ], "VpcId": "vpc-xxx" } ] } { "SecurityGroups": [ { "Description": "xxx-sg", "GroupName": "xxx-sg", "IpPermissions": [ { "FromPort": 80, "IpProtocol": "tcp", "IpRanges": [], "Ipv6Ranges": [], "PrefixListIds": [], "ToPort": 80, "UserIdGroupPairs": [ { "GroupId": "sg-xxx", "UserId": "xxx" } ] }, { "FromPort": 22, "IpProtocol": "tcp", "IpRanges": [ { "CidrIp": "0.0.0.0/0" } ], "Ipv6Ranges": [], "PrefixListIds": [], "ToPort": 22, "UserIdGroupPairs": [] } ], "OwnerId": "xxx", "GroupId": "sg-xxx", "IpPermissionsEgress": [ { "IpProtocol": "-1", "IpRanges": [ { "CidrIp": "0.0.0.0/0" } ], "Ipv6Ranges": [], "PrefixListIds": [], "UserIdGroupPairs": [] } ], "VpcId": "vpc-xxx" } ] }
UserIdGroupPairs配下にあるGroupIdをjqで取得したいのですが、UserIdGroupPairsが空だと下記のようにエラーになります。
$ aws ec2 --profile xxx describe-security-groups --group-ids sg-xxx | jq -r '.SecurityGroups[] | "(.Description),(.IpPermissions[].UserIdGroupPairs.GroupId)"' jq: error (at <stdin>:53): Cannot index array with string "GroupId"
DescriptionとIpPermissions[].UserIdGroupPairs.GroupIdをカンマ区切りで取得しようとしてるのですが難しいでしょうか?
Description,.IpPermissions[].UserIdGroupPairs.GroupId Description,.IpPermissions[].UserIdGroupPairs.GroupId
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。