0

I would like to ask a question in line with above. The cli below works perfectly fine now I would also like to capture two other tags in addition to the 'Name' tag called 'Application' and 'Owner'. How can I change this to add Application and Owner tags to the out-put. So basically:

aws ec2 describe-instances --query "Reservations[].Instances[].[Placement.AvailabilityZone,InstanceId,InstanceType,Platform, State.Name,PrivateIpAddress,StateTransitionReason,Tags[?Key=='Name'] | [0].Value]" --output table

What I am thinking is how do I duplicate Tags[?Key=='Name'] | [0].Value] to make it also pull Application and Owner so in effect Tags[?Key=='Application'] | [0].Value] and Tags[?Key=='Owner'] | [0].Value]? So that when I run the cli it pulls three different tags.

1
  • Frankly, this type of thing is hard to do where not every instance has every tag. You might be better-off with a simple Python script. What are you trying to do with the information once you retrieve it? Quite clearly, table output is not very useful. Commented Apr 15, 2018 at 8:19

3 Answers 3

1

Just add it on...

--query "Reservations[].Instances[].[InstanceId,Tags[?Key=='Name']|[0].Value,Tags[?Key=='Application']|[0].Value,Tags[?Key=='Owner']|[0].Value]"
Sign up to request clarification or add additional context in comments.

4 Comments

John,Thank you very much I tried that but it did not work. Did it work for you? below is what I did aws ec2 describe-instances --query "Reservations[].Instances[].[Placement.AvailabilityZone,InstanceId,InstanceType,Platform,State.Name,PrivateIpAddress,StateTransitionReason,Tags[?Key=='Name'] | [0].Value], Tags[?Key=='Application'] | [0].Value, Tags[?Key=='Owner'] | [0].Value]" --output table
ok the cli below executed but returend None for the owner but I know that tag is there for all instances. --- aws ec2 describe-instances --query "Reservations[].Instances[].[Placement.AvailabilityZone,InstanceId,InstanceType,Platform,State.Name,PrivateIpAddress,StateTransitionReason,Tags[?Key=='Name'] | [0].Value, Tags[?key=='Owner'] | [0].value]" --output table
Can you change your query to: aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,Platform,State.Name,PrivateIpAddress,StateTransitionReason,Tags[?Key==`Name`].Value | [0],Tags[?Key==`Owner`].Value | [0]]' --output table
Krishna - You are spot on by eliminating "Placement.Availability zone" and changing "Tags[?key=='Owner'] | [0].value" TO "Tags[?key=='Owner'].value | [0]" it worked. That worked like Magic. Please explain this change so I can learn I am now able to expand and add more tags I need following same routine. Many thanks to John and Krishna.
0

this works also. (those are back ticks around the key value)

--query 'Snapshots[*].{DES:Description,VOL:VolumeId,VSIZE:VolumeSize,Time:StartTime,ID:SnapshotId,Name:Tags[?Key==Name]|[0].Value,RP:Tags[?Key==retention-period]|[0].Value}'

Comments

0

Fetching Custom tags are really helpful when you try to build something on top of that, like- system or Application configuration based on those, for EaaS, DEaaS, or TEaaS. Hope this will work for you : aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,Platform,State.Name,PrivateIpAddress,StateTransitionReason,Tags[?Key==Application].Value | [0], Tags[?Key==Name].Value | [0],Tags[?Key==Owner].Value | [0]]' --output table –

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.