Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (31 sloc) 1.13 KB
import os
import urllib.request as urllib2
from datetime import datetime
from urllib.request import urlopen
#from urllib2 import urlopen
SITE = os.environ['site'] # URL of the site to check, stored in the site environment variable
EXPECTED = os.environ['expected'] # String expected to be on the page, stored in the expected environment variable
def validate(res):
'''Return False to trigger the canary
Currently this simply checks whether the EXPECTED string is present.
However, you could modify this to perform any number of arbitrary
checks on the contents of SITE.
return b'EXPECTED' in res
def lambda_handler(event, context):
event['time'] =
print('Checking {} at {}...'.format(SITE, event['time']))
if validate(urlopen(SITE).read()):
raise Exception('Validation failed')
print('Check failed!')
print('Check passed!')
return event['time']
print('Check complete at {}'.format(str(
lambda_handler({}, {})