title: aws cli ec2 describe-instances table output
body: <p>I want to run an ec2 describe-instances command and get output in a table format as follows (where name is the Value of the Tag with Key 'Name'):</p>
  
  <pre><code>----------------------------------------------------------
  |                    DescribeInstances                   |
  +-------------+----------------+--------------+----------+
  | instance_id |  ip_address    |    name      |  state   |
  +-------------+----------------+--------------+----------+
  |  i-g93g494d |  99.99.99.01   |  name1       |  running |
  |  i-a93f754c |  99.99.99.02   |  name2       |  running |
  +-------------+----------------+--------------+----------+
  </code></pre>
  
  <p>I can run the following command:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>and obtain output:</p>
  
  <pre><code>[
      [
          {
              "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"
              ]
          }
      ]
  ]
  </code></pre>
  
  <p>However, when I run the same command with --output table rather than --output json I get an error.</p>
  
  <p>command:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>list index out of range
  </code></pre>
  
  <p>I would like the table output to look like the above example but I'm having difficulty solving this.  I'd very much appreciate any help anyone can offer on this.</p>