I am facing this error when I try to run psycopg3 on AWS Lambda.
[ERROR] Runtime.ImportModuleError: Unable to import module 'function': no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found
I reference it as a dependency in my .venv based on this in my setup.py
install_requires=[
'boto3',
'pydantic',
'python-dotenv',
'psycopg',
'twine',
'wheel',
'xlsxwriter'
],
extras_require={
'binary': ['psycopg-binary'],
},
I have copied the installation process as the official site.
As per my understanding, you will need a binary too.
Some External libraries like GPG, psycopg3 require them to be statically compiled as a binary using Amazon Linux 2 OS to run on amazon lambda. You can build it using a docker image and zip it and push as lambda layer to be used in lambda. This process is not straightforward.
Instead I would suggest to take a look at pg8000 driver. https://github.com/tlocke/pg8000
references to use: https://stackoverflow.com/a/72571215/5235168