2

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
JediBig
  • 51
  • 1
  • 4
  • init_oracle_client() isn't useful on Linux. You still need to set LD_LIBRARY_PATH or equivalent _before_ Python starts - read the cx_Oracle doc. There are various other SO questions about AWS that may help you. – Christopher Jones Apr 02 '21 at 23:57
  • 1
    Update: try the latest Python driver, which got renamed from cx_Oracle to python-oracledb: see the [release announcement](https://cjones-oracle.medium.com/open-source-python-thin-driver-for-oracle-database-e82aac7ecf5a). This doesn't need Oracle Instant Client. – Christopher Jones Jul 05 '22 at 22:52

0 Answers0