SSH into EC2 Instances By Instance Id

Make sure you’ve got the aws-cli and jq installed and configured.

Drop this into your .zshrc or .bashrc:

function ec2-ssh () {
  ssh $(aws ec2 describe-instances --filter Name=instance-id,Values=$1 | jq '.Reservations[0].Instances[0].PrivateIpAddress' | tr -d '"')

And now you can ssh into your EC2 instance with:

ec2-ssh i-6g5c7ed4

Follow me on Twitter to keep up with what I’ve learned building my personal finance tool, Stash.

Read more posts …
Written: November 30th, 2015
Categories: ec2, aws