Skip to content

Instantly share code, notes, and snippets.

@kellan
Created July 5, 2016 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellan/59556b91f7ba348e391a882f4c0b613f to your computer and use it in GitHub Desktop.
Save kellan/59556b91f7ba348e391a882f4c0b613f to your computer and use it in GitHub Desktop.
ec2 ssh by instance id
function ec2-ssh () {
FOO=$(aws ec2 describe-instances --filter Name=instance-id,Values=$1 | jq '.Reservations[0].Instances[0].PublicIpAddress,.Reservations[0].Instances[0].\
KeyName' | tr -d '"')
IPADDR=$(echo $FOO | cut -d" " -f1)
KEYNAME=$(echo $FOO | cut -d" " -f2)
ssh -i ~/.ssh/$KEYNAME.pem ec2-user@$IPADDR
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment