Skip to content

Instantly share code, notes, and snippets.

@npazo
Created June 2, 2022 15:29
Show Gist options
  • Save npazo/8db127a24d517c3655c9a8a27dadd7cd to your computer and use it in GitHub Desktop.
Save npazo/8db127a24d517c3655c9a8a27dadd7cd to your computer and use it in GitHub Desktop.
SSH into an EC2 Instance by Instance ID
# Likely needs some tweaks to the `ssh $ip` line to account for key, user, etc.
sshinstance() {
ip=`aws ec2 describe-instances \
--output text \
--instance-id $1 \
--query 'Reservations[*].Instances[*].{Instance:PrivateIpAddress}' \
| tr -d '\r' \
| tr -d '\n'`
ssh $ip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment