Skip to content

Instantly share code, notes, and snippets.

@ericcitaire
Created February 6, 2015 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericcitaire/45515939d81aaee14ed6 to your computer and use it in GitHub Desktop.
Save ericcitaire/45515939d81aaee14ed6 to your computer and use it in GitHub Desktop.
import sys
import boto
import boto.ec2
ec2 = boto.ec2.connect_to_region('eu-west-1')
reservations = ec2.get_all_instances()
def ow_stack(instance):
if 'opsworks:stack' in instance.tags:
return instance.tags['opsworks:stack']
else:
return None
def ow_instance(instance):
if 'opsworks:instance' in instance.tags:
return instance.tags['opsworks:instance']
else:
return None
for reservation in reservations:
for instance in reservation.instances:
if ow_stack(instance) == sys.argv[2] and ow_instance(instance) == sys.argv[3]:
from subprocess import call
call(["ssh", "-i", sys.argv[1], "-l", "ec2-user", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no", "-o", "ServerAliveInterval=5", "-o", "ServerAliveCountMax=1", instance.private_ip_address])
sys.exit(0)
sys.exit("Instance not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment