2

This article was the closest to what I experienced: Connecting to Oracle RDS using AWS Lambda using Python. However, after following all of the steps, I am unable to get a successful result.

Steps on ami-aa5ebdd2 in us-west-2:

sudo yum -y install gcc
mkdir oracle_connect
source oracle_connect/bin/activate
virtualenv oracle_connect
pip install cx_Oracle
wget https://github.com/bumpx/oracle-instantclient/raw/master/instantclient-basic-linux.x64-12.2.0.1.0.zip
mv instantclient_12_2/* oracle_connect/lib/
cd oracle_connect
vi test.py # insert python code here
cp /lib64/libaio.so.1.0.1 lib
ln -s ./lib/libclntsh.so.12.1 ./lib/libclntsh.so
ln -s ./lib/libaio.so.1.0.1 ./lib/libaio.so.1
ln -s ./lib/libaio.so.1.0.1 ./libaio.so.1.0.1
ln -s ./lib/libaio.so.1.0.1 ./libaio.so.1.0.1
cd lib/python2.7/site-packages/
zip -r ~/oracle_connect.zip * .*
cd ~/oracle_connect/lib64/python2.7/site-packages/
zip -r ~/oracle_connect.zip * .*
cd ~/oracle_connect
zip --symlinks -r9 ~/oracle_connect.zip lib/*
zip ~/oracle_connect.zip test.py

The test code is just a cx_Oracle.connect(connection_string) within a lambda handler.

Any advice? I tried to give as much detail as possible. When I try to run this locally, it won't work until I setup: export LD_LIBRARY_PATH=/home/ec2-user/oracle_connect/lib

So I setup the environmental variable on the lambda as: LD_LIBRARY_PATH: /var/task/lib

Taterhead
  • 5,763
  • 4
  • 31
  • 40
  • What's the error/problem? If it's about library paths, can you use ldconfig, as mentioned in https://oracle.github.io/odpi/doc/installation.html#oracle-instant-client-zip (which is linked to from the cx_Oracle install instructions) – Christopher Jones Jan 18 '18 at 21:26
  • On a Lambda, I am unable to do ldconfig as described. Here's the full error message: DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help. I get the same error on the ec2 instance until I export the LD_LIBRARY_PATH – Christopher Gray Jan 18 '18 at 21:42
  • Have you looked into /var/task/lib (which I found by googling, so YMMV)? – Christopher Jones Jan 18 '18 at 21:48
  • Yes, /var/task/lib is exactly where the lib files are placed. Additionally, by default, the files should be part of the path. Thus the reason why I have no idea why it's not working. I used some os commands to validate that all the files were where they were supposed to be. – Christopher Gray Jan 18 '18 at 21:52

1 Answers1

3

So I finally got it working. I re-downloaded the instantclient-basic-linux.x64-12.2.0.1.0.zip from Oracle: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html. I copied the files into the ~/oracle_connect/lib folder. I changed my symlinks to /var/task/lib/(filename) instead of the relative path, and removed the lambda environment variables. Everything works now.