keithrozario / Klayers

Python Packages as AWS Lambda Layers
Other
2.14k stars 309 forks source link

[BUG] Python 3.11 > aws-psycopg2 >> "Unable to import module 'lambda_function': No module named 'psycopg2._psycopg'" #392

Open panos4tw opened 8 months ago

panos4tw commented 8 months ago

Describe the bug I import the module as "import psycopg2" and then I tried to use it as "psycopg2.connect(conn_string)" with no success

Screenshots image

image

image

Layer Version ARN: arn:aws:lambda:eu-central-1:770693421928:layer:Klayers-p311-aws-psycopg2:1

Framework: Console

Additional context

keithrozario commented 8 months ago

Can you share your full code? Is there a lambda_function.lambda_handler method somewhere here?

panos4tw commented 8 months ago

Code looks like this, it's the default AWS Lambda Python boilerplate. I ended up making a layer of my own to make this work:

image

keithrozario commented 8 months ago

Sorry to hear that, will look into this later this week.

iliaaz commented 7 months ago

Hi there! Just ran into the same issue - anything I can do to help debug?

linusliu commented 5 months ago

I also run into the same issue. Add the following layer to a lambda function, python runtime version 3.11; architecture x86_64 arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p311-aws-psycopg2:1

Will return error: Response { "errorMessage": "Unable to import module 'lambda_function': No module named 'psycopg2._psycopg'", "errorType": "Runtime.ImportModuleError", "requestId": "a7956df2-4a44-40c0-a2ea-0ae0e7ca33b7", "stackTrace": [] }