【发布时间】:2015-10-29 11:19:45
【问题描述】:
我想运行一个 ec2 describe-instances 命令并以如下表格格式获取输出(其中名称是带有键“名称”的标签的值):
----------------------------------------------------------
| DescribeInstances |
+-------------+----------------+--------------+----------+
| instance_id | ip_address | name | state |
+-------------+----------------+--------------+----------+
| i-g93g494d | 99.99.99.01 | name1 | running |
| i-a93f754c | 99.99.99.02 | name2 | running |
+-------------+----------------+--------------+----------+
我可以运行以下命令:
aws ec2 describe-instances --instance-ids i-g93g494d i-a93f754c --query "Reservations[*].Instances[*].{name: Tags[?Key=='Name'].Value, instance_id: InstanceId, ip_address: PrivateIpAddress, state: State.Name}" --output json
并获得输出:
[
[
{
"instance_id": "i-g93g494d",
"state": "running",
"ip_address": "99.99.99.01",
"name": [
"name1"
]
}
],
[
{
"instance_id": "i-a93f754c",
"state": "running",
"ip_address": "99.99.99.02",
"name": [
"name2"
]
}
]
]
但是,当我使用 --output table 而不是 --output json 运行相同的命令时,我得到了一个错误。
命令:
aws ec2 describe-instances --instance-ids i-g93g494d i-a93f754c --query "Reservations[*].Instances[*].{name: Tags[?Key=='Name'].Value, instance_id: InstanceId, ip_address: PrivateIpAddress, state: State.Name}" --output json
输出:
list index out of range
我希望表格输出看起来像上面的示例,但我很难解决这个问题。我非常感谢任何人对此提供的任何帮助。
【问题讨论】:
标签: amazon-web-services amazon-ec2 command-line-interface