title: How to access AWS's dynamic EC2 inventory using Fabric?
body: <p>Fabric has a <a href="http://docs.fabfile.org/en/1.10/usage/env.html#hosts" rel="nofollow">hosts</a> setting to specify which computers to SSH into.</p>
  
  <p>Amazon Web Services has more of a dynamic inventory that can be queried in python using tools like <a href="https://boto.readthedocs.org/en/latest/" rel="nofollow">boto</a>.</p>
  
  <p>Is there a way to combine these two services? Ideally, I wanted something as simple as <a href="http://docs.ansible.com/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script" rel="nofollow">ansible</a>'s approach with an inventory file and using an external file like <a href="https://github.com/ansible/ansible/blob/devel/plugins/inventory/ec2.py" rel="nofollow">ec2.py</a>.</p>
  
  <p>More specifically, is there a prebaked solution for this use case? Ideally, I would like to run something straightforward like this:</p>
  
  <pre><code>from fabric.api import env, task
  import ec2
  env.roledefs = ec2.Inventory()
  
  @task
  def command():
      run("lsb_release -a")
  </code></pre>
  
  <p>And run it like so, assuming <code>env.roledefs['nginx']</code> exists:</p>
  
  <pre><code>$ fab -R nginx command
  </code></pre>