I am trying to connect to oracle on rds using lambda with python using cx_oracle package but i get:
ORA-21561: OID generation failed: DatabaseError.
Even after adding file /tmp/HOSTALIASES with the lambda-server-name localhost
. Also added HOSTALIASES
to lambda environment variables. Referd from: AWS Python Lambda with Oracle - OID Generation Failed.
How to resolve this OID generation problem in aws lambda
Here is my code
import cx_Oracle
import os
import sys
import time
# sys.path.append('lib')
# os.environ['ORACLE_SID'] = 'DEVDB'
with open('/tmp/HOSTALIASES', 'w') as hosts_file:
hosts_file.write('{} localhost\n'.format(os.uname()[1]))
def orcl_fetch_records(event, context):
# print (sys.path)
# print (os.listdir(os.getcwd()))
# print (os.environ['LD_LIBRARY_PATH'])
# print (os.environ['ORACLE_HOME'])
# print (sys.path)
print (os.environ['HOSTALIASES'])
with open('/tmp/HOSTALIASES', 'r') as hosts_file:
print hosts_file.read()
dsn = cx_Oracle.makedsn("aws-rds-oracle-server-name", "1521", "SID")
print (dsn)
conn = cx_Oracle.connect("username", "password", dsn)
print ("Oracle DB version = " + conn.version)
cur = conn.cursor()
cur.execute('select * from lambda_test')
for result in cur:
print (result)
cur.close()
conn.close()
Output:
ORA-21561: OID generation failed: DatabaseError Traceback (most recent call last): File "/var/task/orcl_fetch_function.py", line 25, in orcl_fetch_records conn = cx_Oracle.connect("username", "password", dsn) DatabaseError: ORA-21561: OID generation failed