title: Instance Tag Info using boto3 : Getting None object
body: <p>My python code is as follow and need help with the same. Thanks</p>
  
  <pre><code>    import boto3
      import yaml
  
      def get_all_running_instances(unique_name):
          """
          Returns instance data for given instance id.
          :param unique_name:
          :return:
          """
          count = 1
          rname = unique_name.rsplit('-', 1)[0] + '-' + str(count)
          print rname
          ec2 = boto3.resource('ec2')
          instances = ec2.instances.filter(Filters=[{'Name': 'instance-state-name', 'Values': ['running', 'pending']}])
          for instance in instances:
            print(instance.id, instance.instance_type)
          for instance in instances:
            for tag in instance.tags:
                  if rname in tag['Value'] and "Name" in tag['Key']:
                      count = count + 1
                      rname = rname.rsplit('-', 1)[0] + '-' + str(count)
          return count
      x = get_all_running_instances('test-1')
      print x
  </code></pre>
  
  <hr>
  
  <p>Output is as follows and is not able to get the tag information associated with each of the instance. 
  I am running a Lambda on the tag information returned as part of this function.</p>
  
  <pre><code>    ('i-08987804493yyyyyy82', 't2.medium')
      ('i-0e96754xxxxxxxxx', 't2.small')
      Traceback (most recent call last):
        File "dummy.py", line 30, in &lt;module&gt;
          x = get_all_running_instances('test-1')
        File "dummy.py", line 23, in get_all_running_instances
          for tag in instance.tags:
      **TypeError**: 'NoneType' object is not iterable
  </code></pre>