简体   繁体   English

如何从 AWS Lambda 函数 (Python) 建立 Oracle 数据库连接

[英]How to make an Oracle Database connection from an AWS Lambda function (Python)

How does one build the upload package for an AWS Lamba function to connect to an Oracle RDS database?如何为 AWS Lamba 函数构建上传包以连接到 Oracle RDS 数据库? The lambda language is Python 3.6. lambda 语言是 Python 3.6。 My development environment is Windows NOT linux.我的开发环境是 Windows 而不是linux。

When I try, I get error:当我尝试时,出现错误:

DPI-1047: 64-bit Oracle Client library cannot be loaded: "libaio.so.1: cannot open shared object file: No such file or directory

This is strange, because as I understand it, libaio.so is part of the amazon linux system, and so the correct version of libaio.so should be found.这很奇怪,因为据我了解,libaio.so 是亚马逊 linux 系统的一部分,因此应该找到正确版本的 libaio.so。

What I have tried so far到目前为止我尝试过的

I did the following steps to build my lambda package:我执行了以下步骤来构建我的 lambda 包:

  1. Deploy Oracle Instant Client, Basic Lite for Linux x64, version 18.3 into package directory /lib将 Oracle Instant Client, Basic Lite for Linux x64, version 18.3 部署到包目录/lib
  2. Deploy cx_Oracle.so (from pypi website) into package directory /将 cx_Oracle.so(来自 pypi 网站)部署到包目录/
  3. Configure and deploy tnsnames.ora into package directory /配置并部署 tnsnames.ora 到包目录/
  4. Within the lambda, ensure that environment variable LD_LIBRARY_PATH includes /lib and environment variable TNS_ADMIN points to directory /在 lambda 中,确保环境变量LD_LIBRARY_PATH包含/lib并且环境变量TNS_ADMIN指向目录/

here is the fragment of the python code, inside the lambda to achieve that:这是在 lambda 内部实现的 python 代码片段:

oraclePath = os.environ['LAMBDA_TASK_ROOT'] + '/lib'
if oraclePath not in os.environ['LD_LIBRARY_PATH'].split(':'):
  os.environ['LD_LIBRARY_PATH'] = oraclePath + ':' + os.environ['LD_LIBRARY_PATH']
if ('TNS_ADMIN' not in os.environ) or (os.environ['TNS_ADMIN'] != os.environ['LAMBDA_TASK_ROOT']):
  os.environ['TNS_ADMIN'] = os.environ['LAMBDA_TASK_ROOT']
  1. In the lib directory, overwrite-copy libclntsh.so.18.1 to libclntsh.so .在 lib 目录中,将libclntsh.so.18.1覆盖复制到libclntsh.so Similarly for libocci.so , and libclntshcore.so同样对于libocci.solibclntshcore.so

Solutions from others that don't work for me其他人的解决方案对我不起作用

Here are two similiar SO questions with answers that didnt work for me, or are not applicable to my situation:以下是两个类似的 SO 问题,其答案对我不起作用,或不适用于我的情况:

  1. AWS Lambda cannot connect to Oracle Instant Client Paul's solution is done in step 5 above. AWS Lambda 无法连接到 Oracle Instant Client Paul 的解决方案在上面的第 5 步中完成。

  2. AWS Python Lambda with Oracle Thomas's solution is not helpful to me in my situation.在我的情况下,带有 Oracle Thomas 解决方案的AWS Python Lambda对我没有帮助。 These are linux commands.这些是linux命令。 I need a windows solution.我需要一个 Windows 解决方案。

An alternative approach另一种方法

Perhaps I need to ask: How does a windows developer acquire the correct version of libaio.so.1 for the Amazon Linux Lambda environment, and where should this file be placed in the lambda package?或许我需要问一下:windows 开发人员如何获取适用于 Amazon Linux Lambda 环境的正确版本的 libaio.so.1,该文件应该放在 lambda 包中的什么位置? Any solution that involves bash commands is not helpful.任何涉及 bash 命令的解决方案都没有帮助。

Since I ran into the same problem, you can find the needed libraries from here: https://pkgs.org/download/libaio (eg the Arch linux package)由于我遇到了同样的问题,您可以从这里找到所需的库: https : //pkgs.org/download/libaio (例如 Arch linux 包)

Then extract the files from that package into the /lib folder of your lambda package.然后将该包中的文件提取到 lambda 包的 /lib 文件夹中。

Download instant client basic lite for windows x64.. that error will get solved!下载适用于 Windows x64 的即时客户端基本精简版 .. 该错误将得到解决! As u have downloaded linux version and using it on windows.. you are getting that error.因为你已经下载了 linux 版本并在 windows 上使用它.. 你得到了那个错误。

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

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