Thomas Scott-Kunkel Thomas Scott-Kunkel - 1 month ago 33x
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 and cx_Oracle-5.2.1-py2.7.egg-info (created on 64bit AWX Linux). I also added the files from into local/lib in that zip file.

The error I am getting is

import cx_Oracle

ImportError: 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 "{}"'.format(libdir, oracledir, args), shell=True) starts with
import cx_Oracle


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