"2014-01-30T12:44:57.000Z i-xxxxxxxx" "2014-01-31T08:19:33.000Z i-xxxxxxxx" "2014-01-31T08:19:38.000Z i-xxxxxxxx" "2014-01-31T12:33:27.000Z i-xxxxxxxx" "2014-01-31T12:33:27.000Z i-xxxxxxxx" "2014-01-31T14:50:01.000Z i-xxxxxxxx" "2014-01-31T14:50:06.000Z i-xxxxxxxx"
You can do the filtering natively in the aws cli, without using jq (although jq is awesome!) Show Sample Output
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.
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.
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
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:
aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'
This manage to list all private ip address, instance id and ALL tags which I don't need. I just need the name.aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b | jq '.Reservations[].Instances[] | {PrivateIpAddress, InstanceId, Tags}'
I'm not sure why I can't execute command like yours in this way:aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags[?Key==`Name`].Value[]'
This works but its showing all the Tags Key namesaws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags'
aws ec2 describe-instances --filters "Name=vpc-id,Values=vpc-e2f17e8b" "Name=instance-state-name,Values=running" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress,InstanceId ]' --output table
Note: 1. I have an extra filter in there that only queries for running instances. You can change that to whatever you'd like. 2. You can add on to the query portion if you'd like other information (e.g., remove the filter of instance-state-name, and instead add on after the instance-id section this: State.Name). You could also add things like the AZ , e.g.,aws ec2 describe-instances --filters "Name=vpc-id,Values=vpc-e2f17e8b" "Name=instance-state-name,Values=running" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress,InstanceId,State.Name,Placement.AvailabilityZone ]' --output table
aws ec2 describe-instances --filters "Name=vpc-id,Values=vpc-e2f17e8b" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress,InstanceId,State.Name,Placement.AvailabilityZone ]' --output table