我想向外部 API 发送发布请求(https://example.com/api/jobs/test) 每隔一小时。
我使用的Lambda函数如下:
Handler: index.lambda_handler
python: 3.6
index.py
import requests
def lambda_handler(event, context):
url="https://example.com/api/jobs/test"
response = requests.post(url)
print(response.text) #TEXT/HTML
print(response.status_code, response.reason) #HTTP
测试事件:
{
"url": "https://example.com/api/jobs/test"
}
Error:
START RequestId: 370eecb5-bfda-11e7-a2ed-373c1a03c17d Version: $LATEST
Unable to import module 'index': No module named 'requests'
END RequestId: 370eecb5-bfda-11e7-a2ed-373c1a03c17d
REPORT RequestId: 370eecb5-bfda-11e7-a2ed-373c1a03c17d Duration: 0.65 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 21 MB
任何帮助,将不胜感激。
供应商requests
现在已从botocore
.
考虑将您的 Lambda 代码打包为requirements.txt
使用 CloudFormation 包或 SAM CLI 打包功能。
我以前的答案在售出之前requests
弃用:
您或许可以利用requests
模块从boto
库,而无需安装或打包您的函数。
考虑这个导入:import botocore.vendored.requests as requests
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)