Skip to content

Instantly share code, notes, and snippets.

@tokudu
Created October 27, 2012 23:55
Show Gist options
  • Save tokudu/3966918 to your computer and use it in GitHub Desktop.
Save tokudu/3966918 to your computer and use it in GitHub Desktop.
A helper script for SSH'ing into EC2 instances by name
#!/bin/bash
# SSH into an EC2 instance by name
# Author: tokudu@github.com (SoThree.com).
set -e
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` instance_name"
exit 1
fi
# get instance id
instance_name=$1
# get the instance address so that we can SSH into it
echo "Obtaining the instance address..."
instance_address=`ec2-describe-instances --filter "tag:Name=${instance_name}" | grep INSTANCE | awk '{print $4}'`
echo "Done. Instance address: ${instance_address}"
ssh ${instance_address}
@rclayton-the-terrible
Copy link

Many thanks.

@rclayton-the-terrible
Copy link

Is this using an old version of the AWS console API? I working through a couple of small issues, one being that ec2-describe-instances is now aws ec2 describe-instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment