Last active
September 13, 2018 13:45
-
-
Save jvalduvieco/4fdcb483c681e54e3e7aa90af156c4a2 to your computer and use it in GitHub Desktop.
A little tool to ssh into AWS machines that lets you select profile, region and machine
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 | |
# ssh-aws [profile] [region] [machine_name] | |
if [ -z $1 ]; then | |
PROFILE=$(cat $HOME/.aws/credentials|grep -e "^\[" |sed -e 's/\[//; s/\]//'|percol) | |
else | |
PROFILE=$1 | |
fi | |
if [ -z $2 ]; then | |
REGION=$(echo "US West (Oregon) Region us-west-2 | |
US West (N. California) Region us-west-1 | |
US East (Ohio) Region us-east-2 | |
US East (N. Virginia) Region us-east-1 | |
Asia Pacific (Mumbai) Region ap-south-1 | |
Asia Pacific (Seoul) Region ap-northeast-2 | |
Asia Pacific (Singapore) Region ap-southeast-1 | |
Asia Pacific (Sydney) Region ap-southeast-2 | |
Asia Pacific (Tokyo) Region ap-northeast-1 | |
Canada (Central) Region ca-central-1 | |
China (Beijing) Region cn-north-1 | |
EU (Frankfurt) Region eu-central-1 | |
EU (Ireland) Region eu-west-1 | |
EU (London) Region eu-west-2 | |
EU (Paris) Region eu-west-3 | |
South America (São Paulo) Region sa-east-1 | |
AWS GovCloud (US) us-gov-west-1" | percol | awk '{print $NF}') | |
else | |
REGION=$2 | |
fi | |
if [ -z $3 ]; then | |
IP=$(aws ec2 describe-instances --profile=$PROFILE --region=$REGION --query "Reservations[*].Instances[*].[PublicIpAddress, Tags[?Key=='Name'].Value|[0]]" --output text|percol | cut -f 1 ) | |
echo "Connecting to $IP..." | |
else | |
IP=$(aws ec2 describe-instances --profile=$PROFILE --region=$REGION --filters="Name=tag:Name,Values=$3" --query "Reservations[*].Instances[*].PublicIpAddress" --output=text | head -n 1) | |
fi | |
ssh ec2-user@$IP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment