SSH into EC2 instances via tag name
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 46 commits ahead of facebookarchive:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitignore
.travis.yml
HISTORY.rst
LICENSE
MANIFEST.in
README.rst
ec2_ssh.py
requirements.in
requirements.txt
setup.cfg
setup.py
tox.ini

README.rst

ec2-ssh

https://travis-ci.org/adamchainz/ec2-ssh.svg?branch=master

A pair of command line utilities for finding and SSH-ing into your Amazon EC2 instances by tag (such as 'Name').

Forked from Instagram original code by YPlan.

Installation

From pip:

pip install ec2-ssh

Python 2 and 3 compatible.

Usage

There are two utilities: ec2-ssh and ec2-host.

1. ec2-ssh

Use the ec2-ssh command to SSH into your instances. Rather than a hostname to SSH into, it takes a tag key (default Name) and value, looks up the instances matching that tag, randomly picks one (if there is >1) and uses its public hostname, or private IP if it's not public. The username is defaulted to ubuntu.

For example:

$ ec2-ssh myapp
# looks up instances where Name=myapp, expands out to something like:
# ssh ubuntu@ec2-123-45-67-89.compute-1.amazonaws.com

$ ec2-ssh root@myapp
# expands to
# ssh root@ec2-123-45-67-89.compute-1.amazonaws.com

You can pass the -t / --tag option to use a different tag key to search on, for example:

$ ec2-ssh -t role myapp-frontend

All other options are passed through to SSH so you can do things like:

$ ec2-ssh myapp -- sudo systemctl restart nginx
$ ec2-ssh -vvv myapp  # why can't I connect??

2. ec2-host

This tool exposes just the host-lookup logic from ec2-ssh you can use it for other purposes. The only difference is that rather than returning just one matching instance's hostname/IP, it will return all of them. For example:

$ ec2-host  # no tag, prints all instance hosts
ec2-123-45-67-89.compute-1.amazonaws.com
ec2-123-45-67-90.compute-1.amazonaws.com
ec2-123-45-67-91.compute-1.amazonaws.com

% ec2-host myapp  # only instances where Name=myapp
ec2-123-45-67-89.compute-1.amazonaws.com
ec2-123-45-67-90.compute-1.amazonaws.com

% ec2-host -t environment prod  # instances where environment=prod
ec2-123-45-67-90.compute-1.amazonaws.com
ec2-111-45-67-90.compute-1.amazonaws.com