The closest I have get is using the following commands.
This command manage to lists all name of instances.
aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-e2f17e8b --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'
This command 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 this way:
aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags[?Key==`Name`].Value[]'
This command works but its showing all the Tags Key names.
aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.PrivateIpAddress + " " + .InstanceId + " " + .Tags'
You need to escape the backslashes in order to format the answer correctly.
So this is the actual command you want:
And you don't need
.Value[]
. You can just use.Value
, and that will give the same output.This is awesome, btw. I will be implementing this myself!
CORRECTION: The above won't work if the value of
.Value
is "None". This works better:Try this
The above answers are OK, but my favorite of the same is;
in fact, one can place it in a BASH function list list;
then simply call from the prompt as 'awsls'
Something like this?
I added a filter for instance state "running". Posting it here in case that's helpful for anyone.
My use case is slightly different, I'm generating Ansible host files so I just want private IP # name on all running hosts.
Adding this for folks that will find this post when searching for how to get your instance info. You can add VPC in the select statement to receive that as well.
In powershell you can use:
With the AWS CLI you can use: