问题描述
我正在 Cloud9 中编写 Python Lambda。 尝试运行它(在本地,在部署到后端之前),我收到此错误:
Invalid lambda response received: Invalid API Gateway Response Keys: {'errorType','errorMessage'} in {'errorMessage': "Unable to import module 'getPersonByKey': No module named 'requests'",'errorType': 'Runtime.ImportModuleError'}
我没有在我的代码中使用请求,也没有导入它,它没有包含在 requirements.txt 文件中。
这是我的 Lambda 代码:
import json
import pyTigergraphBeta as tg
def lambda_handler(event,context):
try:
conn = tg.TigergraphConnection(host="https://skillblaster-dev.i.tgcloud.io",graphname="SkillBlasterDev",useCert=True)
conn.apiToken = conn.getToken("rak++++++++++41f")[0]
print("Calling to run installed query")
result = conn.runInstalledQuery("getPersonByKey",{"keyPerson":"[email protected]"})
except Exception as e:
print(e)
raise e
return {
"statusCode": 200,"body": json.dumps("TEST"),}
我错过了什么?
解决方法
很可能 pyTigerGraphBeta
库在幕后使用了 requests
库。我遇到过几次这个问题。
解决方案会将 requests
库添加到您的 requirements.txt(或您使用的任何包管理器 - 诗歌、pip、pipenv)中,因此它将最终出现在 zip 文件中您的 lambda 代码是(您上传到 s3 的)。