SSH into EC2 instance with instance ID

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

Drop this function 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:

$ ec2-ssh i-6g5c7ed4

Written: November 30th, 2015
Tags: ops
Read more posts …