Use aws cli exclusively to query useful information about instances in a VPC

aws ec2 describe-instances --filters "Name=vpc-id,Values=<replace_with_id>" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress,InstanceId,State.Name,Placement.AvailabilityZone ]' --output table
Following in the steps of a few other scripts on here, I thought I'd mix in the ability to add in an instance tag output into this. This can be super useful if you are using the "Name" tag as a hostname tag and feeding that into, say Route53 for DNS to reach the machine. Helps for scripting against later.
Sample Output
------------------------------------------------------------------------------------------
|                                    DescribeInstances                                   |
+-------------------------------+----------------+-------------+----------+--------------+
|  server01          |  10.64.45.18  |  i-333456s5 |  running |  us-west-2a              |
|  server01          |  10.64.12.21  |  i-besd8a48 |  running |  us-west-2b              |
|  server03          |  10.64.32.20  |  i-bf09ca49 |  running |  us-west-2c              |
|  server04          |  10.64.18.65  |  i-0as345cf |  running |  us-west-2a              |
|  server05          |  10.64.16.95  |  i-25c456e3 |  stopped |  us-west-2b              |
|  server06          |  10.64.36.75  |  i-33c986f5 |  stopped |  us-west-2c              |
|  server07          |  10.64.66.80  |  i-ccc2340a |  stopped |  us-west-2a              |
+-------------------------------+----------------+-------------+----------+--------------+

0
By: fydgit
2015-08-27 21:52:58

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

Considering A New Car?

You should consider a Tesla. Get 6 Months Free Supercharging.

Free Supercharging

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: