Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions bin/ec2-ssh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ set -e

usage() {
cat<<EOF
Usage: ec2-ssh [-k KEY] [-s SECRET] [-r REGION] [-t TAG] <instance-name>
Usage: ec2-ssh [-k KEY] [-s SECRET] [-r REGION] [-i IDENTITY_FILE] [-t TAG] <instance-name>

Open an ssh connection to an EC2 instance where <instance-name>=tag:value.
The 'tag:' portion of <instance-name> is optional, and defaults to 'Name'.
For a list of instances, run ec2-host without any paramteres

-h display this help and exit
-k, KEY Amazon EC2 Key, defaults to \$AWS_ACCESS_KEY_ID
-s, SECRET Amazon EC2 Secret, defaults to \$AWS_SECRET_ACCESS_KEY
-r, REGION Amazon EC2 Region, defaults to us-east-1
-t, TAG Tag name for searching, defaults to 'Name'
-h display this help and exit
-k, KEY Amazon EC2 Key, defaults to \$AWS_ACCESS_KEY_ID
-s, SECRET Amazon EC2 Secret, defaults to \$AWS_SECRET_ACCESS_KEY
-r, REGION Amazon EC2 Region, defaults to us-east-1
-i, IDENTITY_FILE Amazon EC2 Identity File, defaults to \$HOME/.ssh/id_rsa
-t, TAG Tag name for searching, defaults to 'Name'
EOF
}

Expand All @@ -23,13 +24,14 @@ test $# -eq 0 && { usage; exit; }

# Process options
cmd="ec2-host"
while getopts ":hk:s:r:t:" opt; do
while getopts ":hk:s:r:t:i:" opt; do
case $opt in
h ) usage; exit 1;;
k ) cmd="$cmd -k $OPTARG";;
s ) cmd="$cmd -s $OPTARG";;
r ) cmd="$cmd -r $OPTARG";;
t ) cmd="$cmd -t $OPTARG";;
i ) identity_file=$OPTARG;;
\? ) usage; exit 1
esac
done
Expand Down Expand Up @@ -67,4 +69,6 @@ cmd="echo \\\". ~/.bashrc && PS1='\[\e]0;$inst: \w\\\a\]\[\\\033[01;32m\]$inst\[
if test "${@:2}"; then
cmd="${@:2}"
fi
test -n "$host" && echo "Connecting to $host." && exec sh -c "ssh -t $user@$host \"$cmd\""
opts="-t"
test -n "$identity_file" && opts="-i $identity_file $opts"
test -n "$host" && echo "Connecting to $host." && exec sh -c "ssh $opts $user@$host \"$cmd\""
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* 1.1.1 - Add line echoing host before establishing SSH connection
* 1.2 - Merged pull requests to add region and tag support
* 1.2.1 - Fix issue when ec2-host finds one offline instance with same name as an online instance
* 1.2.2 - Add support for identity file
"""


Expand All @@ -52,7 +53,7 @@

setup(
name = "ec2-ssh",
version = "1.2.1",
version = "1.2.2",
author = "Shayne Sweeney",
author_email = "shayne@instagram.com",
description = "SSH into EC2 instances via tag name",
Expand Down