I have a requirement in which I need to connect to oracle database and get some data from db table. So as I am a beginner in aws lambda so i started with below example.
import cx_Oracle
import os
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
logger.info('begin lambda_handler')
dsn = cx_Oracle.makedsn("hostname", "1521", "sid")
con = cx_Oracle.connect("user_id", "password", dsn)
cur = con.cursor()
#logger.info('username: ' + username)
#logger.info('host: ' + host)
sql = """SELECT COUNT(*) AS TEST_COUNT FROM DUAL"""
cur.execute(sql)
columns = [i[0] for i in cur.description]
rows = [dict(zip(columns, row)) for row in cur]
logger.info(rows)
con.close()
logger.info('end lambda_handler')
return "Successfully connected to oracle."
I created below structure in linux for creating deployment package.
Parent_Directory
-lib(Under this library i placed all the oracle instant client files)
-cx_oracle files
lmbda_function.py
after deploying the package on aws lambda and testing it, I get below error.
[ERROR] DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "/var/task/lib/libclntsh.so: file too short". See https://oracle.github.io/odpi/doc/installation.html#linux for help Traceback (most recent call last): File "/var/task/lambda_function.py", line 29, in lambda_handler
Please somebody help me to achieve this, also if there is any better option to connect with oracle from aws lambda than please share.