Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the server name with aws ec2 describe-instances

I'm able to get the instance id, instance type, and public ip address into a table format. But I'm unable to parse the Tags Name. We plug in names for all of our servers to make them easier to identify.

Here's an example of what I've come up with so far

aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress]' --output table

------------------------------------------------
|               DescribeInstances              |
+------------+-------------+-------------------+
|  i-64629700|  m1.small   |  54.227.243.165   |
|  i-2d300249|  m3.xlarge  |  23.23.166.230    |
|  i-7422c909|  m1.small   |  23.21.105.175    |
|  i-08c76e24|  m3.xlarge  |  54.235.253.163   |
|  i-99a20a72|  m3.medium  |  23.23.184.200    |
|  i-6053991b|  m1.large   |  54.221.250.189   |

Not sure how I would add something like this into the table

'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'
like image 920
hfranco Avatar asked Sep 18 '14 21:09

hfranco


People also ask

What is my EC2 server name?

You can see the hostname values for an existing EC2 instance in the Details tab for the EC2 instance: Hostname type: The hostname in IP name or resource name format. Private IP DNS name (IPv4 only): The IP name that will always resolve to the private IPv4 address of the instance.

What is my AWS instance name?

Open the Amazon Connect console at https://console.aws.amazon.com/connect/ . On the instances page, the instance name appears in the Instance Alias column. This instance name appears in the URL you use to access Amazon Connect.

Is an EC2 instance a server?

An Amazon EC2 instance is a virtual server in Amazon's Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure.


1 Answers

You're very close. Try this:

aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress,Tags[?Key==`Name`]| [0].Value]' --output table
like image 89
Ben Whaley Avatar answered Oct 28 '22 13:10

Ben Whaley