I have a python program that run in loop to count the number of keys in bucket, it works fine when It has one or more keys. It throws an error when it has 0 objects.
def CdmCount(Destbucket):
global key
totalcdms = 0
for key in Destbucket.get_all_keys():
totalcdms += 1
print totalcdms
assert isinstance (key,object )
return (totalcdms, key)
I see following error:
File "check_fun.py", line 24, in CdmCount
return (totalcdms, key)
NameError: global name 'key' is not defined
Complete code http://pastebin.com/QrAwL4Dq
Update:
After I add a upper level boto function to list the number of keys exist, if its zero exit.
keys = list(Destbucket.list())
if not keys:
print "List is empty"
sys.exit(2)
Is it a good approach?