我對AWS很新,我遇到了一些問題。這是我的代碼:AWS python lambda函數:沒有模塊命名請求
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
該文件的名稱是lambda_function.py;我在stackoverflow上檢查過類似的問題,有人提到我必須更改文件命名。但它沒有幫助。這裏是如何命名python方法:
這是我得到的錯誤: START RequestId: cf24e9be-bbef-11e7-97b4-d9b586307f3e Version: $LATEST Unable to import module 'lambda_function': No module named requests
而當試圖打印它給我一個語法錯誤。對不起格式。有什麼建議麼?
'requests'不在標準庫中。您需要了解如何在該平臺上提供依賴關係;例如,通常使用'requirements.txt'文件來指定它們。看看例如http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html – jonrsharpe
@jonrsharpe我在我的機器上安裝了虛擬環境。我應該上傳一切嗎'pip install -r requirements.txt'? – inson