title: Filtering ec2-instances with boto
body: <p>I use tags to keep track of my EC2 instances, such as (Project, Environment). I have a use case where I need to filter only those instances that belong to a specific project and to a specific environment.</p>
  
  <p>When I use filter with boto and pass these two values I get a result that does a OR rather than a AND of the filters and so I am receiving a list of instances that belong to different projects but same environment. </p>
  
  <p>Now I can use two lists and then compare the instances in each and get the desired set of instances, but is there a better way of getting this done?</p>
  
  <p>Here is what i am doing:</p>
  
  <pre><code>conn = ec2.EC2Connection('us-east-1',aws_access_key_id='XXX',aws_secret_access_key='YYY')
  reservations = conn.get_all_instances(filters={"tag-key":"project","tag-value":&lt;project-name&gt;,"tag-key":"env","tag-value":&lt;env-name&gt;})
  instances = [i for r in reservations for i in r.instances]
  </code></pre>
  
  <p>Now the instance list that I am getting gives all the instances from the specified project irrespective of the environment and all the instances from the specified environment irrespective of the project.</p>