How to Extract Multiple Ec2 Instance Tags

How to Extract Multiple Ec2 Instance Tags

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

3 Answers

Just add it on...

--query "Reservations[].Instances[].[InstanceId,Tags[?Key=='Name']|[0].Value,Tags[?Key=='Application']|[0].Value,Tags[?Key=='Owner']|[0].Value]"
4

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}'

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 –

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.