Tuesday, January 21, 2014

Getting Instance Details at a Glance with awscli

The Nova command line interface has me completely spoiled. After becoming so used to 'nova list', the usual output of EC2's 'describe instances' makes me feel... disparaged.

Here's a one-liner I assembled to give a Nova-like experience with awscli (i.e. I just need a few high-level details of all my instances).

aws ec2 describe-instances --profile my-profile --output table --query \
'Reservations[*].{\
id:Instances[0].InstanceId,\
key:Instances[0].KeyName,\
security_group:Instances[0].SecurityGroups[0].GroupName,\
public_ip:Instances[0].PublicIpAddress,\
status:Instances[0].State.Name,\
name:Instances[0].Tags[0].Value}'

This yields output like the following:

---------------------------------------------------------------------------------------------------
|                                        DescribeInstances                                        |
+------------+--------------------+-----------------+--------------+------------------+-----------+
|     id     |        key         |      name       |  public_ip   | security_group   |  status   |
+------------+--------------------+-----------------+--------------+------------------+-----------+
|  i-3dd9871f|  user-01-dev       |  salt-master-01 |  192.168.1.1 |  linux           |  running  |
|  i-41173864|  user-34-dev       |  None           |  None        |  mine            |  stopped  |
|  i-3001421a|  user-02-dev       |  toolbox        |  None        |  apache          |  stopped  |
+------------+--------------------+-----------------+--------------+------------------+-----------+

That is all.

No comments:

Post a Comment