I have a Lambda Python 3.6 function that checks for the existence of a specific tag and value on EC2 instances. The tag is “expenddate” and the value will either be blank of have a date formatted in mm/dd/yy format. My goal is to have the function check for the existence of the tag and then process when two conditions are met, 1) if the date is less than or equal to the current date and 2) the value is not blank (None). This processes correctly based on the date but still reports back when the value is blank which I don’t want.
Here is relevant part of my code, specifically line ‘if (tag['Value']) <= mdy and (tag['Value']) != None:’.
for instance in ec2.instances.all():
if instance.tags is None:
continue
for tag in instance.tags:
if tag['Key'] == 'expenddate':
expiredInstances=[]
if (tag['Value']) <= mdy and (tag['Value']) != None:
print('Sending publish message')
sns_client.publish(
TopicArn = 'arn:aws:sns:us-east-1:704819628235:EOTSS-Monitor-Tag-Exceptions1',
Subject = '!!!! Tag Exception has Expired.',
Message = str("The tag exception for instance %s has expired in account %s" % (instance.id,acctnum)))
else:
print ("end")
return "sucess"