mercredi 15 juin 2016

boto3 TypeError: 'NoneType' object is not iterable


I'm trying to use boto3 to print the values of an EC2 tag I have called 'Function' but receive a TypeError: 'NoneType' object is not iterable error in line 7 after the code runs through about 20 objects. I've tried to catch this by checking if that value is None but still receive this error.

import boto3
s = boto3.Session(profile_name='default')
ec2 = s.resource('ec2')

for i in ec2.instances.all():
  for tag in i.tags:
    if tag['Value'] is None:
      print("No Value")
    else:
      if tag['Key'] == 'Function':
        print(tag['Value'])

Aucun commentaire:

Enregistrer un commentaire