Created
September 9, 2018 10:12
-
-
Save daniel-woods/58fc74ca21a45ea86b56982529e4c6ed to your computer and use it in GitHub Desktop.
Use the AWSCLI to parse the Public IP from a describe-instances call to connect via SSH.
This file contains hidden or 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 | |
| # Default user uses different names, depending on OS. | |
| # Amazon Linux = "ec2-user" | |
| # Ubuntu = "ubuntu" | |
| remote_user="ec2-user" | |
| pem="/home/.ssh/YOUR_PRIVATE_KEY" | |
| port=22 | |
| # Get this using describe_instances, or via the AWS Console. | |
| instance="i-YOUR_AWS_INSTANCE_ID" | |
| ssh $(aws ec2 describe-instances --instance-id $instance --query Reservations[].Instances[].NetworkInterfaces[].Association[].PublicIp[] | cut -c 6- | rev | cut -c 2- | rev) -l $remote_user -i $pem -p $port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment