我想在多个级别的aws ec2 describe-instances API中进行查询。例如,我想结合:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[ImageId, InstanceType, KeyName, State.Name, PublicIpAddress, NetworkInterfaces.Groups.GroupName]' --output json
和诸如OwnerId之类的字段,位于Instances之上。
答案 0 :(得分:0)
您可以在OwnerId
之前指定顶级Instances[*]
:
aws ec2 describe-instances --query 'Reservations[*].[OwnerId,Instances[*].[ImageId, InstanceType, KeyName, State.Name, PublicIpAddress, NetworkInterfaces.Groups.GroupName]]' --output json
但是,实例之间存在一对多关系这一事实意味着它将在更高级别返回:
[
[
"123456789012",
[
[
"ami-48d38c2b",
"t2.micro",
"class",
"running",
"54.2.33.44",
null
]
]
],
[
"123456789012",
[
[
"ami-f806349b",
"t2.small",
"class",
"running",
"54.1.22.33",
null
]
]
]
]
顺便说一下,OwnerId
仅仅是拥有资源的AWS账户的ID,在几乎每种情况下,它都是相同的值。