I have a python boto3 code as below:
for rule in event_rules:
if rule.startswith('Something'):
print('[INFO] Proceeding!...')
describe_rule = self.cw_event.describe_rule(
Name=rule
)
if describe_rule['State'] == 'ENABLED':
state = True
break
else:
state = False
return state
.
.
.
if check == True:
print('[INFO] SUCCESS' )
else:
print('[INFO] FAILED')
Here check is the class function which calls the above block from its function.I am pretty confident on the function and class part. In this case when a rule is present and is in ENABLED state,code is successfull. If the conditions are not matching, it throws out an error as follows:
UnboundLocalError: local variable 'state' referenced before assignment
I am not able to figure it out. I went through this answer : UnBoundLocalError: Local Variable Referenced Before Assignment [Counter] and gave state as global, but still failed.