Thomas Scott-Kunkel Thomas Scott-Kunkel - 3 months ago 60
Python Question

AWS Python Lambda with Oracle

I am trying to connect to an Oracle db from AWS Lambda using python. I managed to package cx_Oracle but the environment is not finding the dependencies.

I had zipped the content, which contained cx_Oracle.so and cx_Oracle-5.2.1-py2.7.egg-info (created on 64bit AWX Linux). I also added the files from instantclient-basic-linux.x64-12.1.0.2.0.zip into local/lib in that zip file.

The error I am getting is

import cx_Oracle

ImportError: libaio.so.1: cannot open shared object file: No such file or directory

I am dynamically changing the environment variable in python such as:

oracledir = os.path.join(os.getcwd(), 'local', 'lib')
libdir = os.environ['LD_LIBRARY_PATH'] + ":" + os.path.join(os.getcwd(), 'local', 'lib')

command = 'LD_LIBRARY_PATH={} ORACLE_HOME={} python OracleWorker.py "{}"'.format(libdir, oracledir, args)
subprocess.call(command, shell=True)


OracleWorker.py starts with
import cx_Oracle

Answer

Resolved. Added all dependencies by running ldd cx_Oracle.so| grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination Added all those files in destination to lib folder in lambda zip

Comments