2

I'm trying to get the OwnerId, StackId, and InstanceId output on the same line. I run the below command with the --output-text option, and it puts the "some_stack" data on a different line.

aws ec2 describe-instances --profile 1234 --filters "Name=image-id,Values=ami-asdf" --query 'Reservations[*].[OwnerId, Instances[0].Tags[?Key==`StackId`].Value[], Instances[0].InstanceId]'

When I run the command without the --output-text option, I can see that "some_stack" is in an array, even though I put [] on .Value to try and flatten it. What am I doing wrong?

Output:

[
    [
        "1234",
        [
            "some_stack"
        ],
        "i-ghjk"
    ]
]
jars99
  • 25
  • 4

1 Answers1

2

Tags is an array, so you need to flatten it with array | [0]:

aws ec2 describe-instances  --query 'Reservations[*].[OwnerId, Instances[0].Tags[?Key==`StackId`].Value|[0], Instances[0].InstanceId]' --output text
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470