Skip to content

Instantly share code, notes, and snippets.

@mefellows
Created May 1, 2015 06:32
Show Gist options
  • Save mefellows/7826a7f5868faa4ba7d3 to your computer and use it in GitHub Desktop.
Save mefellows/7826a7f5868faa4ba7d3 to your computer and use it in GitHub Desktop.
AWS EC2 SSH onto an instance with one command, given an instance id
#!/bin/bash
INSTANCE_ID=$1
IP=$(aws ec2 --region $AWS_REGION describe-instances --instance-id $INSTANCE_ID | jq -r .Reservations[0].Instances[0].PrivateIpAddress)
KEYPAIR_NAME=$(aws ec2 --region $AWS_REGION describe-instances --instance-id $INSTANCE_ID | jq -r .Reservations[0].Instances[0].KeyName)
ssh -i ~/.ssh/$KEYPAIR_NAME.pem "ec2-user@$IP"
@mefellows
Copy link
Author

Note, that you you need jq installed.

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