pythonaws-lambdapsycopg2python-3.8psycopg3

Unable to import module 'lambda_function': No module named 'psycopg2._psycopg aws lambda function


I have installed the psycopg2 with this command in my package folder :

pip install --target ./package psycopg2 # Or
pip install -t ./package psycopg2

now psycopg2 module is in my package and I have created the zip and upload it in AWS lambda.

In my local sprint is working fine but on AWS lambda it was not working.

It shows me error

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

my lambda code is

import psycopg2

def lambda_handler():
   print('hello')

my all other modules are working fine


Solution

  • add this lib

    pip install aws-psycopg2