Use JQ to get a csv list of assets in aws with security groups, names, and ENI ID for tracking VPC Flows from JSON

cat aws.json | jq -r '.Reservations[].Instances[] | [.PrivateIpAddress, .SecurityGroups[].GroupId,.SecurityGroups[].GroupName,.NetworkInterfaces[].NetworkInterfaceId,(.Tags[] | select(.Key =="Name") | .Value),([.InstanceId| tostring] | join(";"))]|@csv'
You need to use the aws ec2 describe instances to get the JSON file.
Sample Output
"1.1.1.1","sg-9bc42fed","private-my-groupname","eni-81519d01","qa-myserver-1.pholem-earth.com","i-0129e27fa464a213c"
"2.2.2.2","sg-93b42b1c","another-security-group","eni-31c53b29","gc-myadmin-server-2.pholem-earth.com","i-0b5ac9579a692f987"

0
By: symgryph
2018-08-08 19:22:58
cat

What Others Think

You won't believe how long it took to get this figured out. The main trick was figuring out that I needed to turn the array (instanceid) to a string before the magic of @csv could come into play.
symgryph · 1 week ago

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.

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: