title: Python deployment using Fabric
body: <p>I'm learning to use <strong>Fabric</strong> and <strong>Boto</strong> so far I have managed to login and create an new instance. How do I now pip install Gunicorn on the newly created server below using Python in same fab file?</p>
  
  <p>i.e. I'm hoping to get the new instance and pip install from this file.</p>
  
  <p>This is my fab.py file and what I have so far:</p>
  
  <pre><code>SERVER_TYPES = {
                  'web' : {
                         'image_id' : 'ami-xxxxxx',
                         'instance_type' : 't1.micro',
                         'security_groups' : [MAIN_SG],
                         'key_name' : MAIN_KP,
                          },
  }
  
  
  
  class EC2Conn:
      def __init__(self):
          print(_green("Started..."))
          self.ec2conn = None
          self.user = 'fabUser'
          self.access_key = 'xxxxxx'
          self.secret_key = 'xxxxxxxxxxxx'
  
      def connect(self):
          print(_green("Connecting..."))
  
          region = ec2.get_region('eu-west-1')
          self.ec2conn = ec2.connection.EC2Connection(self.access_key,
                            self.secret_key, region=region)
  
  
      def get_instances(self):
          return self.ec2conn.get_all_instances()
  
  
      def create_instance(self, instance_type='web', address=None):
                  reservation = self.ec2conn.run_instances( **SERVER_TYPES[instance_type])
                  print reservation
                  instance = reservation.instances[0]
                  time.sleep(10)
                  while instance.state != 'running':
                          time.sleep(5)
                          instance.update()
                          print "Instance state: %s" % (instance.state)
  
                  print "instance %s done!" % (instance.id)
  
  
  
  def create_instance():
      a = EC2Conn()
      a.connect()
      return a.create_instance()
  </code></pre>
  
  <p>So I'm after something like this:</p>
  
  <pre><code>def install_stuff(using self.ec2conn)
        using ec2 instance
        run('pip install gunicorn')
  
     etc
  </code></pre>