title: Using JMESPath and aws ec2 describe instances to output multiple tag values
body: <p>I'm trying to output multiple tags from an ec2 instances description. The tag values that I want are Name and aws:autoscaling:groupName.</p>
  
  <pre><code> "Tags": [
                          {
                              "Value": "somename", 
                              "Key": "Name"
                          }, 
                          {
                              "Value": "some-asg-name", 
                              "Key": "aws:autoscaling:groupName"
                          }, 
                          {
                              "Value": "somethingelse", 
                              "Key": "project"
                          }
                      ], 
  </code></pre>
  
  <p>Here's what I have so far: </p>
  
  <pre><code>aws ec2 describe-instances --instance-ids i-12345678 --query 'Reservations[].Instances[].[Tags[? contains(`["aws:autoscaling:groupName","Name"]`, Key)] | [0].Value,[1].Value,InstanceId]' --output text
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>somename       None    i-12345678
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>somename       some-asg-name    i-12345678
  </code></pre>
  
  <p>I tried both double pipe <code>||</code> and <code>contains</code> but can't get the output I need. Also, I'm not sure <code>[1].Value</code> is the right way to get the 2nd matching tag.</p>