Created
July 3, 2015 23:22
-
-
Save z0mbix/7c35f73e567be2fd597e to your computer and use it in GitHub Desktop.
SSH to an EC2 instance by name
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
#!/usr/bin/env bash | |
# | |
# SSH to an EC2 instance by name | |
# | |
# You need the AWS cli (pip install awscli) | |
# | |
if [[ -z $1 ]]; then | |
echo 'You must specify an instance name!' | |
exit 1 | |
fi | |
name=$1 | |
instance=$(aws ec2 describe-instances \ | |
--output=text \ | |
--query 'Reservations[*].Instances[*].[PublicIpAddress]' \ | |
--filters "Name=tag:Name,Values=$name") | |
if [[ -z $instance ]]; then | |
echo "Instance $name not found!" | |
exit 1 | |
fi | |
ssh $instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment