AWSラムダを使用してcronjobスタイルのHTTPリクエストを作成したいと考えています。残念ながら私はPythonを知らない。単純なHTTPリクエストを行うLambda関数
私は彼らが私が望むものに似ているような "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ラムダコンソールまたはCLIを使用して頻度を指定することをご理解ください。関数名を尋ねられたら、 " .lambda_handler"を指定すると、指定した頻度で上記の関数が呼び出されます。 –