If you have read my previous posts, somehow, I always end up bringing up AWS. Although it is not the only service I use nor am I in any way related to it, I do use it very often. Often enough that I might spend a few hours putting something together that can save me a few keystrokes every day. And that’s exactly what I did with EC2 CLI.
If you have ever tried Elastic Beanstalk, an AWS service that bundles together a bunch of other AWS services to create a very easy to use (yet flexible) platform to deploy your web apps, you probably stumbled upon their eb tools. This command line interface, among other tools, allows you to easily SSH into one of your Elastic Beanstalk instances by using eb ssh and selecting an instance.

$ eb ssh
Select an instance to ssh into
1) i-96133799
2) i-5931e053
(default is 1): 1


I’ve found this to be extremely useful, specially when working with hundreds of instances and autobalance active, so that instances might be replaced at any moment.
Unfortunately, most of my instances are not part of an Elastic Beanstalk environment and I’ve found myself wasting a few minutes every day just to find the details to connect to a certain instance (I admit, it is mainly my fault, but it does become hard to manage huge lists of hosts). That’s why I took sometime to develop a similar tool that can give me the same sort of SSH functionality, but applied to all EC2 instances. I called it ec2-cli. (Whoooaa, so original!!)

Using EC2-CLI

ec2-cli is a very simple tool, I haven’t added much into it (at least not at the moment of writing this post). I’ve just developed enough to make it stable and working.
The CLI was written in Javascript and made available in NPM, the project is also available as open source at https://github.com/Colex/ec2-cli.
You must have node and npm installed in your machine to set it up. Here is how you install it:

$ npm install -g ec2-cli

Now you should be able to run it using ec2 ssh:

$ ec2 ssh
0) i-96133799 (webapp)
1) i-9623c2a9 (dashboard)
2) i-12asc243 (spark-slave)
3) i-d12ccaa3 (spark-slave)
4) i-ha23667k (spark-master)
5) i-c13bs23b (cron-server)
6) i-bddf1acc (zookeeper1)
7) i-aa999caa (zookeeper2)
8) i-7d77c891 (zookeeper3)
9) i-b24a12cd (mesos)
Use the arrows to navigate up and down or ESC to exit
Select a row [0-9]:

Very simple! As I said before, not much into it. I have added a set of options that gives you a bit more control, you can read more about them in the project’s repository page: https://github.com/Colex/ec2-cli.
Out of all the options, I think the most important one is the ability to filter your instances by their name. When dealing with hundreds of instances, listing and navigating through all of them can become overwhelming. For this reason, I felt the need of adding this option early on (–name).

$ ec2 ssh -n spark
2) i-5931e053 (spark-slave)
3) i-5931e053 (spark-slave)
4) i-5931e053 (spark-master)
Use the arrows to navigate up and down or ESC to exit
Select a row [0-9]:

Notes

Although ec2-cli was based on eb tools, it does not offer everything eb tools does. For instance, if your instance does not have the SSH port open for inbound traffic, eb will try to open it for your IP only and close it once you exit. That’s a nice thing to have, but it is not supported at the moment on ec2-cli. Feel free to contribute if you feel like it could become a helpful tool for you as well.

@AlexCorreia