Thursday 27 March 2014

ssh config generator for aws instance using python boto

import boto.ec2

# NOTE: if you don't put the key at conn then it will search for
# your profile file, if not /etc/boto.cfg if not your varible 'BOTO_CONFIG=/file/path'

conn=boto.ec2.connect_to_region('us-east-1')
#conn=boto.ec2.connect_to_region('us-east-1',aws_access_key_id='key' , aws_secret_access_key='key')

# Following is the prod key: [ Full access ]
#AWS_ACCESS_KEY_ID = 'key'
#AWS_SECRET_ACCESS_KEY = 'key'


reservations = conn.get_all_instances()
for res in reservations:
    for inst in res.instances:
            print "%s \t %s" % ("Host", inst.tags['Name'])
            print "%s  %s" % ("HostName", inst.public_dns_name)
            print "%s" % ("StrictHostKeyChecking no")
            print "%s  %s" % ("Port", "1717")
            print "%s %s" % ("User", "ubuntu")
            print "%s %s%s.%s\n" % ("IdentityFile", "/path/of/folder/", inst.key_name, "pem" )
            #print "%s" % (inst.tags['Name'])

No comments:

Post a Comment