1

I am trying to use the psycopg2 library with AWS lambda in my Pycharm IDE on Windows 10.

I have tried all versions of Python listed in this repository and I still always get the following error:

{"errorMessage": "Unable to import module 'app': No module named 'psycopg2._psycopg'", "errorType": "Runtime.ImportModuleError", "stackTrace": []}

I have tried this solution where we install aws-psycopg2 but it did not work. As per this solution, I have ensured that my local Python runtime and the Lambda runtime are the same and I still get the error.

I have made sure that my Python version is 64 bit as per this answer

knowledge_seeker
  • 811
  • 1
  • 8
  • 18

1 Answers1

1

Hey incase it still didn't work, i faced the same issue here's what i did:

  • ran this command:
  • pip install --platform=manylinux1_x86_64 --only-binary=:all: psycopg2-binary --target psycopg-binary/python/lib/python3.8/site-packages

  • created a lambda layer with the above package (pyscopg-binary) and added it to the lambda function
  • make sure runtimes are correct ( at first i had the lamda layer runtime 3.9 and the function 3.9, then i switched both to 3.8 and it worked)
  • Im not absolutely sure aside from the runtimes which of the packages caused it to work (since i did multiple things in one step: added aws-psycopg2 to the requirements.txt in addition to changing runtime, hence im not sure if the aws-psycopg2 had anything to do with it working :), but i think that it has nothing to do with it, so it should work without it).

hope this helps.

whitebat 199
  • 172
  • 2
  • 9