Last active
February 9, 2016 00:46
-
-
Save keturn/61f76adaaedf4d0eb0b7 to your computer and use it in GitHub Desktop.
ssh to an AWS EC2 host by its group name.
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 | |
# requires AWS CLI: https://aws.amazon.com/cli/ | |
# and jq: https://stedolan.github.io/jq/ | |
set -e | |
EC2_NAME="$1" | |
if [ -z "${EC2_NAME}" ] ; then | |
echo Usage: "$0" '<ec2-name> [ssh args ...]' | |
fi | |
shift | |
EC2_HOSTNAME=$(aws --output json ec2 describe-network-interfaces --filter "Name=group-name,Values=${EC2_NAME}" | | |
jq --raw-output --exit-status '.NetworkInterfaces[0].Association.PublicDnsName') | |
exec ssh "ec2-${EC2_NAME}" -o HostName="${EC2_HOSTNAME}" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment