AWS 람다를 사용하여 cronjob 스타일의 HTTP 요청을 만들고 싶습니다. 불행히도 나는 파이썬을 모른다.간단한 HTTP 요청을하는 람다 함수
나는 그들이 내가 원한 것과 비슷한 것으로 보이는 "Canary"기능을 가지고있는 것을 발견했다. 단순히 HTTP 요청을하기 위해 어떻게 단순화합니까? PHP 파일을 트리거하면됩니다.
from __future__ import print_function
from datetime import datetime
from urllib2 import urlopen
SITE = 'https://www.amazon.com/' # URL of the site to check
EXPECTED = 'Online Shopping' # String expected to be on the page
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 EXPECTED in res
def lambda_handler(event, context):
print('Checking {} at {}...'.format(SITE, event['time']))
try:
if not validate(urlopen(SITE).read()):
raise Exception('Validation failed')
except:
print('Check failed!')
raise
else:
print('Check passed!')
return event['time']
finally:
print('Check complete at {}'.format(str(datetime.now())))
덕분에 도움 - 나는 그런 간단한 일을 물어 그래서 바보가 된 기분하지만 난 Python을 배운 적이하고 내가 아는 모든 언어는 목록 :)에없는 –
윌 주파수 설정이 실행 람다에요? 이 기능은 어디에 설정되어 있습니까? –
필자는 AWS Lambda 콘솔 또는 CLI를 사용하여 빈도를 지정하는 것으로 알고 있습니다. 함수 이름을 묻는 질문에 " .lambda_handler"를 지정하면 위의 함수가 지정한 빈도로 호출됩니다. –