我对 AWS 还很陌生,遇到了一些问题。这是我的代码:
from __future__ import print_function
from urllib2 import Request, urlopen, URLError
import requests
import boto3
import json
def lambda_handler(event, context):
url = "https://globalcurrencies.xignite.com/xGlobalCurrencies.json/GetHistoricalRatesRange?Symbol=BTCUSD&PriceType=Mid&StartDate=01/01/2017&EndDate=10/27/2017&PeriodType=Daily&FixingTime=22:00&_token=some_token_xyz"
response = requests.get(url).json()
# print json.dumps(response, indent=4) # gives a syntax error
return response
Name of the file is lambda_function.py; I have checked similar problems on stackoverflow and some mentioned that I have to change the file naming. But it didn't help. Here is how python method was named:
Here is the error I am getting:
START RequestId: cf24e9be-bbef-11e7-97b4-d9b586307f3e Version: $LATEST
Unable to import module 'lambda_function': No module named requests
And when try to print it gives me a syntax error. Sorry for the formatting. Any suggestions?
requests 不是 AWS lambda 中的标准库。
所以有两种方法可以解决这个问题:
1-从 Botocore 库堆栈将其导入为:(给出答案后不推荐使用的选项)
from botocore.vendored import requests
Here https://gist.github.com/gene1wood/4a052f39490fae00e0c3有一个可以在 lambda 中导入的所有可用库的列表
2- Create https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html带有 virtualenv 的部署包。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)