我需要在python脚本中进行休息调用,每天运行一次.我无法使用AWS Lambdas将"requests"包打包到我的python-package中.我收到错误:"无法导入模块'lambda_function':没有名为lambda_function的模块"
我把它分解为hello_world预定义脚本.我可以把它打包成拉链并上传.一切正常.一旦我将"导入请求"放入文件中,我就会收到此错误.
这是我已经做过的事情:
一切的命名如下:
我想在最后运行的文件如下所示:
import requests
import json
def lambda_handler(event, context):
url = 'xxx.elasticbeanstalk.com/users/login'
headers = {"content-type": "application/json", "Authorization": "Basic Zxxxxxxxxx3NjxxZxxxxzcw==" }
response = requests.put(url, headers=headers, verify=False)
return 'hello lambda_handler'
Run Code Online (Sandbox Code Playgroud)
我很高兴能得到任何帮助.我已经在这个问题上使用了多个小时.
我有一个用于向另一个端点发出 HTTP POST 请求的 AWS Lambda 函数的 Python 脚本。由于Python的urllib2.request,https://docs.python.org/2/library/urllib2.html,只能在标准处理数据application/x-www-form-urlencoded格式,我要张贴JSON数据,我使用的请求库,https://pypi.org /project/requests/2.7.0/。
该请求库在 Python 运行时环境中的 AWS Lambda 中不可用,因此必须通过from botocore.vendored import requests. 到现在为止还挺好。
今天,我收到了一个弃用警告:
DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'.
This is not a public API in botocore and will be removed in the future.
Additionally, this version of requests is out of date. We recommend you install the
requests package, 'import requests' directly, and use the requests.post() function instead. …Run Code Online (Sandbox Code Playgroud) 我想使用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): …Run Code Online (Sandbox Code Playgroud)