Created
June 2, 2022 15:29
-
-
Save npazo/8db127a24d517c3655c9a8a27dadd7cd to your computer and use it in GitHub Desktop.
SSH into an EC2 Instance by 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
# 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