Skip to content

Instantly share code, notes, and snippets.

@masaki925
Last active December 25, 2018 05:58
Show Gist options
  • Save masaki925/def5afec52994783068708aab7bbbb6b to your computer and use it in GitHub Desktop.
Save masaki925/def5afec52994783068708aab7bbbb6b to your computer and use it in GitHub Desktop.
AWS Lambda URL Monitor
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