Last active
August 21, 2018 20:26
-
-
Save afraenkel/23205862a13f6c3a0267cddb42f4c8b0 to your computer and use it in GitHub Desktop.
start an ssh tunnel to an ec2-instance given the name of the instance
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 | |
# need aws commandline interface installed (do "pip install awscli") | |
# need aws credentials set-up | |
# usage: start-tunnel.sh <INSTANCE-NAME> | |
instance_name=$1 | |
key_name=$(aws ec2 \ | |
describe-instances \ | |
--profile personal \ | |
--region us-west-2 \ | |
--filters "Name=tag:Name,Values=${instance_name}" "Name=instance-state-name,Values=running" \ | |
--query "Reservations[0].Instances[0].KeyName" \ | |
--output text) | |
public_dns=$(aws ec2 \ | |
describe-instances \ | |
--profile personal \ | |
--region us-west-2 \ | |
--filters "Name=tag:Name,Values=${instance_name}" "Name=instance-state-name,Values=running" \ | |
--query "Reservations[0].Instances[0].PublicDnsName" \ | |
--output text) | |
ssh -N -f -L localhost:8888:localhost:8888 -i ~/.ssh/${key_name}.pem ubuntu@${public_dns} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment