Last active
May 10, 2017 08:09
-
-
Save fredsted/41b1870c98fab48d52346b9f36641f6c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
# Installation: | |
# - Install `boto`: pip install -U boto | |
# - Configure EC2 credentials: see http://boto.cloudhackers.com/en/latest/getting_started.html#configuring-boto-credentials | |
# - Configure username or SSH args below | |
# These things are configurable | |
region = 'eu-central-1' | |
ssh_username = 'simonfredsted' | |
ssh_args = '-A -D1091' | |
import boto.ec2, sys, os | |
if len(sys.argv) != 2: | |
print 'Usage: ec2connect.py [hostname]' | |
sys.exit() | |
hostname = sys.argv[1] | |
instances = {} | |
for reservation in boto.ec2.connect_to_region(region).get_all_reservations(): | |
for instance in reservation.instances: | |
instances[instance.tags['Name']] = instance.ip_address | |
if instances[hostname] == None: | |
print 'Host not found or stopped' | |
sys.exit() | |
os.system("ssh "+ ssh_args +" "+ ssh_username + "@" + instances[hostname]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment