I am trying to import the Psycopg2 library into a lambda function but everytime it continues to fail, I have tried pip installing the library then zipping it with the .py file, it fails… with “”Unable to import module ‘lambda_function’: No module named ‘psycopg2._psycopg'”. Then I tried to use Docker and create a container to identical to the runtime of lambda, and it failed with the same error msg, I even tried to create my own Layer and it still continues to fail, here is the Code for importing and getting a connection (which it never makes it too):
And I also tried with Psycopg-Binary which should counter any compatability issues with the lambda runtime but it still failes
import sys
import psycopg2
import boto3
import json
import os
try:
connection = psycopg2.connect(host = os.environ\["host"\],
user= os.environ\["username"\],
password = os.environ\["password"\],
dbname = os.environ\["dbname"\],
port = os.environ\["port"\])
# except psycopg2.Error as e:
print(f"Connection Attempt Failed, error: {e}")
Things I have tried:
- Tried zipping the .py file and the libraries
- Tried Docker and getting the right versions of everything.
- Tried using Psycopg-binary
- Tried making and using a layer with Psycopg2
- Tried using an already community built layer for psyocpg2
Did all of these things, and it still does not work,
Any help appreciated, ty.