I'm trying to access oracle db in lambda using python using cx_Oracle library. Since oracle needs os specific client to connect, I also downloaded the instant client and add it as a layer in AWS. Problem is I'm seeing this error that wouldn't budge
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory"
lambda_handler.py
import cx_Oracle
import os
def lambda_handler(event, context):
dsn = cx_Oracle.makedsn('url', 1521)
con = cx_Oracle.connect(user='user', password='1234', dsn=dsn)
cursor = con.cursor()
cursor.execute('SELECT * FROM DEVICES')
return {
'statusCode': 200,
'body': cursor.fetchall()
}
I've seen other thread to add init_oracle_client, so I've addedcx_Oracle.init_oracle_client(lib_dir='/opt/instantclient_21_1')
since Lambda Layer is placed on "/opt" directory, it seems that it found the file, but it produces similar error. Notice the file different
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libnnz21.so: cannot open shared object file: No such file or directory"
According to my understanding, since I put the lib_dir specifically, the file supposed to be '/opt/instantclient_21_1/libnnz21.so' which is there, but for some reason Oracle try to find that library in the current runtime directory.
NOTE I'm using:
- Python 3.8
- Instant Client Lite for Linux x86-64
- cx_Oracle-8.1.0-cp39-cp39-manylinux1_x86_64