Created
May 1, 2015 06:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, that you you need jq installed.