gpt4 book ai didi

php - 用于发出简单 HTTP 请求的 Lambda 函数

转载 作者:行者123 更新时间:2023-11-28 20:04:07 25 4
gpt4 key购买 nike

我想使用 AWS lambda 发出 cronjob 样式的 HTTP 请求。很遗憾,我不懂 Python。

我发现他们有一个“金丝雀”功能,似乎与我想要的相似。我如何简化它以简单地发出 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())))

最佳答案

该程序将“简单地发出 HTTP 请求。”

from urllib2 import urlopen

SITE = 'https://www.amazon.com/' # URL of the site to check

def lambda_handler(event, context):
urlopen(SITE)

关于php - 用于发出简单 HTTP 请求的 Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37819525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com