1

The cli below works perfectly now I would also like to capture two other tags in addition to 'Name' called 'Application' and 'Environment'. How can I change this to add Application and Environment tags to the out-put.

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

1 Answer 1

1

You can accomplish this by adding filters to your query:

aws ec2 describe-instances --query "Reservations[].Instances[].
  [Placement.AvailabilityZone,InstanceId,InstanceType,Platform,
   State.Name,PrivateIpAddress,StateTransitionReason]" 
    --filters "Name=tag:Name,Values=my-name" "Name=tag:env,Values=prod" 
     --output table"

This will return only the instances tagged with Name == my-name and env == prod

1
  • MrDuk thank you very much for your feedback so my intent is not to filter out anything but to get the additional tags of environment and that of function as additional col. So I want a way to modify my original query to add additional tags. So this part of the query Tags[?Key=='Name'] | [0].Value] displays the Name tag as a col so all the instances will show what their respective name. I want those other two tags also displayed as col such that each row will show an instance per row with all the information associated with the instance as defined in the query.
    – Abi
    Mar 20, 2018 at 14:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.