Last active
December 25, 2018 05:58
-
-
Save masaki925/def5afec52994783068708aab7bbbb6b to your computer and use it in GitHub Desktop.
AWS Lambda URL Monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import urlopen | |
from datetime import datetime, timedelta | |
def validate(expected, res): | |
return expected in str(res) | |
def lambda_handler(event, context): | |
try: | |
if not validate(event['expected'], urlopen(event['site']).read()): | |
raise Exception('Validation failed') | |
except: | |
print('Check failed!') | |
raise | |
else: | |
print('Check passed!') | |
return 'OK' | |
finally: | |
print('Check complete at {}'.format(str(datetime.utcnow() + timedelta(hours=9)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment