document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import argparse
  2. import boto
  3.  
  4. parser = argparse.ArgumentParser(description=\'Launch ec2 instances\')
  5. parser.add_argument(\'--access-key\', type=str, metavar=\'key\', help=\'Your AWS Access Key\', action=\'store\')
  6. parser.add_argument(\'--secret\', type=str, metavar=\'secret\', help=\'Your AWS secret\', action=\'store\')
  7. parser.add_argument(\'--keypair\', type=str, metavar=\'keyfile\', help=\'Stored Keypair\', action=\'store\')
  8. parser.add_argument(\'--image\', type=str, metavar=\'ami\', help=\'AMI Image id\', action=\'store\')
  9. parsed = parser.parse_args()
  10.  
  11. try:
  12.     ec2 = boto.connect_ec2(parsed.key, parsed.secret)
  13.     packages = """#/bin/sh
  14.    apt-get update
  15.    apt-get -y install nginx zsh"""
  16.     reservation = ec2.run_instances(image_id=parsed.ami, key_name=parsed.keyfile, user_data = packages)
  17.     for r in ec2.get_all_instances():
  18.         if r.id == reservation.id:
  19.             break
  20.     print r.instances[0].public_ip
  21. except AttributeError, e:
  22.     parser.print_help()
');