0

I am writing a Python Lambda in Cloud9. Trying to run it (locally, before deploying to the backend), I'm receiving this error:

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'}

I am NOT using requests in my code, not importing it, it is not included in the requirements.txt file.

This is my Lambda code:

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":"mor@excellench.com"})

    except Exception as e:
        print(e)    
        raise e

    return {
        "statusCode": 200,
        "body": json.dumps("TEST"),
    }

What am I missing?

Mor Sagmon
  • 905
  • 1
  • 16
  • 35

1 Answers1

0

Most likely the pyTigerGraphBeta lib uses requests library under the hood. I faced this issue couple of times.

The Solution would be adding requests library to your requirements.txt (or whatever package manager you use - poetry, pip, pipenv) so it will end up in the zip file where your lambda code is (that you upload to s3).

Vladyslav Sheruda
  • 1,856
  • 18
  • 26
  • @James thanks. Adding it to requirements did nothing. I tried pip install - saying it is already satisfied, with a list of folders it exists. I have no access to these folders. Ideas? – Mor Sagmon Jan 12 '21 at 16:49
  • @MorSagmon In my requirements.txt I have line `requests==2.24.0` and pip installs it. I feel like you are installing it globally, instead you should have your own virtualenv that will contain all your packages. Please, check this answers, It should help you https://stackoverflow.com/questions/7225900/how-to-install-packages-using-pip-according-to-the-requirements-txt-file-from-a – Vladyslav Sheruda Jan 12 '21 at 17:15