title: Can I filter volumes by instance_id in boto?
body: <p>I'm trying to copy volumes from one instance to another using Python's 'boto' module. Part of that process is identifying the volumes attached to an instance. There are a couple ways to approach this problem. For example, I could use list comprehension:</p>
  
  <pre><code>from boto.ec2 import connect_to_region
  conn = connect_to_region('us-east-1')
  all_volumes = conn.get_all_volumes()
  instance_volumes = [v for v in all_volumes if v.attach_data.instance_id = "&lt;instanceID&gt;"]
  </code></pre>
  
  <p>This works, and works well enough for my purposes. All the same, I'm curious if there's a way to use <code>get_all_volumes()</code>'s <a href="http://boto.cloudhackers.com/en/latest/ref/ec2.html#boto.ec2.connection.EC2Connection.get_all_volumes" rel="nofollow">built-in filtering</a> to get the same result. For example, if I were searching for instances whose "Name" tag match a certain pattern, I could do this:</p>
  
  <pre><code>filters = {'tag:Name': '&lt;name&gt;'}
  reservations = self.conn.get_all_instances(filters=filters)
  instances = [i for r in reservations for i in r.instances]
  </code></pre>
  
  <p><code>get_all_volumes()</code> has a similar filter parameter, but I can't get it to work on <code>boto.ec2.volume.Volume.attach_data.instance_id</code>. Am I missing something obvious or is filtering by instance_id on volumes not possible?</p>