简体   繁体   中英

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? The lambda language is Python 3.6. My development environment is Windows NOT 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.

What I have tried so far

I did the following steps to build my lambda package:

  1. Deploy Oracle Instant Client, Basic Lite for Linux x64, version 18.3 into package directory /lib
  2. Deploy cx_Oracle.so (from pypi website) into package directory /
  3. Configure and deploy tnsnames.ora into package directory /
  4. Within the lambda, ensure that environment variable LD_LIBRARY_PATH includes /lib and environment variable TNS_ADMIN points to directory /

here is the fragment of the python code, inside the lambda to achieve that:

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 . Similarly for libocci.so , and libclntshcore.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:

  1. AWS Lambda cannot connect to Oracle Instant Client Paul's solution is done in step 5 above.

  2. AWS Python Lambda with Oracle Thomas's solution is not helpful to me in my situation. These are linux commands. I need a windows solution.

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? Any solution that involves bash commands is not helpful.

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)

Then extract the files from that package into the /lib folder of your lambda package.

Download instant client basic lite for windows x64.. that error will get solved! As u have downloaded linux version and using it on windows.. you are getting that error.

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