简体   繁体   中英

AWS Lambda Layer for connect Oracle Database

I'm trying to create an AWS Lamda Layer with Python to work with Oracle Database but several articles I found and answers here on stackoverflow didn't give me a solution to the problem:

cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help.

If I set "ORACLE_HOME" in addition to "LD_LIBRARY_PATH" the error points to another lib:

cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libnnz21.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help

I'm using pytest to view the details of the outputs. With "ORACLE_HOME" and "LD_LIBRARY_PATH" set I get this:

------------------------------------------------------- Captured stderr call -------------------------------------------------------
ODPI [04150] 2022-07-05 08:27:21.959: Context Parameters:
ODPI [04150] 2022-07-05 08:27:21.959: Environment Variables:
ODPI [04150] 2022-07-05 08:27:21.959:     ORACLE_HOME => "/home/dev/xxxxxx/PythonLayer/python"
ODPI [04150] 2022-07-05 08:27:21.959:     LD_LIBRARY_PATH => "/home/dev/xxxxx/PythonLayer/python/lib"
ODPI [04150] 2022-07-05 08:27:21.959: check module directory
ODPI [04150] 2022-07-05 08:27:21.959: module name is /home/dev/xxxxx/.venv/lib/python3.9/site-packages/cx_Oracle.cpython-39-x86_64-linux-gnu.so
ODPI [04150] 2022-07-05 08:27:21.959: load in dir /home/dev/xxxxx/.venv/lib/python3.9/site-packages
ODPI [04150] 2022-07-05 08:27:21.959: load with name /home/dev/xxxxx/.venv/lib/python3.9/site-packages/libclntsh.so
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: /home/dev/xxxxx/.venv/lib/python3.9/site-packages/libclntsh.so: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.959: load with OS search heuristics
ODPI [04150] 2022-07-05 08:27:21.959: load with name libclntsh.so
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: libclntsh.so: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.959: load with name libclntsh.so.19.1
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: libclntsh.so.19.1: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.959: load with name libclntsh.so.18.1
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: libclntsh.so.18.1: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.959: load with name libclntsh.so.12.1
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: libclntsh.so.12.1: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.959: load with name libclntsh.so.11.1
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: libclntsh.so.11.1: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.959: load with name libclntsh.so.20.1
ODPI [04150] 2022-07-05 08:27:21.959: load by OS failure: libclntsh.so.20.1: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.960: load with name libclntsh.so.21.1
ODPI [04150] 2022-07-05 08:27:21.960: load by OS failure: libclntsh.so.21.1: cannot open shared object file: No such file or directory
ODPI [04150] 2022-07-05 08:27:21.960: check ORACLE_HOME
ODPI [04150] 2022-07-05 08:27:21.960: load in dir /home/dev/xxxxx/PythonLayer/python/lib
ODPI [04150] 2022-07-05 08:27:21.960: load with name /home/dev/xxxxx/PythonLayer/python/lib/libclntsh.so
ODPI [04150] 2022-07-05 08:27:21.960: load by OS failure: libnnz21.so: cannot open shared object file: No such file or directory
===================================================== short test summary info ======================================================
FAILED tests/cliente_oracle_test.py::testar_conexao_objeto_banco_oracle - TypeError: 'DatabaseError' object is not iterable

Without "ORACLE_HOME":

ODPI [04208] 2022-07-05 08:30:56.228: Context Parameters:
ODPI [04208] 2022-07-05 08:30:56.228: Environment Variables:
ODPI [04208] 2022-07-05 08:30:56.228:     LD_LIBRARY_PATH => "/home/dev/yudqs/PythonLayerTratamentoDados/python/lib"
ODPI [04208] 2022-07-05 08:30:56.228: check module directory
ODPI [04208] 2022-07-05 08:30:56.228: module name is /home/dev/yudqs/.venv/lib/python3.9/site-packages/cx_Oracle.cpython-39-x86_64-linux-gnu.so
ODPI [04208] 2022-07-05 08:30:56.228: load in dir /home/dev/yudqs/.venv/lib/python3.9/site-packages
ODPI [04208] 2022-07-05 08:30:56.228: load with name /home/dev/yudqs/.venv/lib/python3.9/site-packages/libclntsh.so
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: /home/dev/yudqs/.venv/lib/python3.9/site-packages/libclntsh.so: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with OS search heuristics
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so.19.1
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so.19.1: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so.18.1
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so.18.1: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so.12.1
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so.12.1: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so.11.1
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so.11.1: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so.20.1
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so.20.1: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: load with name libclntsh.so.21.1
ODPI [04208] 2022-07-05 08:30:56.228: load by OS failure: libclntsh.so.21.1: cannot open shared object file: No such file or directory
ODPI [04208] 2022-07-05 08:30:56.228: check ORACLE_HOME
===================================================== short test summary info ======================================================
FAILED tests/cliente_oracle_test.py::testar_conexao_objeto_banco_oracle - TypeError: 'DatabaseError' object is not iterable

I'm using WSL with Amazon Linux 2; I have installed libaio and copy to my lib path. In my init .py I put the following:

lib_dir = pathlib.Path(__file__).parent.parent.joinpath('lib').as_posix()
sys.path.append(pathlib.Path(__file__).parent.parent.as_posix())
sys.path.append(lib_dir)
os.environ['LD_LIBRARY_PATH']=lib_dir
os.environ['ORACLE_HOME']=pathlib.Path(__file__).parent.parent.as_posix()
os.environ['DPI_DEBUG_LEVEL']='64'

Best option is to use the latest cx_Oracle version which doesn't need Oracle Client libaries .

The driver got renamed to python-oracledb .
See the release announcement .

On Linux, you need to set LD_LIBRARY_PATH before an application starts. But if you use the latest driver this variable isn't needed.

If you need to use cx_Oracle, then update your question with what's in /home/dev/xxxxx/PythonLayer/python/lib . Have you installed Oracle Instant Client which is what will provide libclntsh.so etc? Also, when using Instant Client don't set ORACLE_HOME.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM