简体   繁体   English

用于连接 Oracle 数据库的 AWS Lambda 层

[英]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:我正在尝试使用 Python 创建一个 AWS Lamda 层以与 Oracle 数据库一起使用,但我在 stackoverflow 上找到的几篇文章和答案并没有为我提供解决问题的方法:

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". cx_Oracle.DatabaseError:DPI-1047:找不到 64 位 Oracle 客户端库:“libclntsh.so:无法打开共享对象文件:没有这样的文件或目录”。 See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help.请参阅https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html获取帮助。

If I set "ORACLE_HOME" in addition to "LD_LIBRARY_PATH" the error points to another lib:如果我在“LD_LIBRARY_PATH”之外设置“ORACLE_HOME”,则错误指向另一个库:

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". cx_Oracle.DatabaseError:DPI-1047:找不到 64 位 Oracle 客户端库:“libnnz21.so:无法打开共享对象文件:没有这样的文件或目录”。 See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help请参阅https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html获取帮助

I'm using pytest to view the details of the outputs.我正在使用 pytest 查看输出的详细信息。 With "ORACLE_HOME" and "LD_LIBRARY_PATH" set I get this:设置“ORACLE_HOME”和“LD_LIBRARY_PATH”后,我得到了这个:

------------------------------------------------------- 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":没有“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;我将 WSL 与 Amazon Linux 2 一起使用; I have installed libaio and copy to my lib path.我已经安装了 libaio 并复制到我的 lib 路径。 In my init .py I put the following:在我的init .py 中,我输入了以下内容:

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 .最好的选择是使用不需要 Oracle Client libaries的最新 cx_Oracle 版本。

The driver got renamed to python-oracledb .驱动程序重命名为python-oracledb
See the release announcement .请参阅发布公告

On Linux, you need to set LD_LIBRARY_PATH before an application starts.在 Linux 上,您需要在应用程序启动之前设置 LD_LIBRARY_PATH。 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 .如果您需要使用 cx_Oracle,请使用/home/dev/xxxxx/PythonLayer/python/lib中的内容更新您的问题。 Have you installed Oracle Instant Client which is what will provide libclntsh.so etc?您是否安装了将提供 libclntsh.so 等的 Oracle Instant Client? Also, when using Instant Client don't set ORACLE_HOME.此外,使用 Instant Client 时不要设置 ORACLE_HOME。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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