Skip to content

Instantly share code, notes, and snippets.

@yureative
Created March 3, 2015 06:47
Show Gist options
  • Save yureative/8a3f58369e2a253efe6f to your computer and use it in GitHub Desktop.
Save yureative/8a3f58369e2a253efe6f to your computer and use it in GitHub Desktop.
SSH login to EC2 instances by Name Tag
#!/bin/bash
if [ $# -lt 1 ]
then
echo 'Usage: c INSTANCE_NAME [REMOTE_COMMANDS...]'
exit 1
fi
pdns=`aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" | jq -r '.Reservations[].Instances[].PrivateDnsName'`
shift
ssh ec2-user@$pdns $@
@yureative
Copy link
Author

You first need to configure AWS region and credentials with aws configure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment