0
votes

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

2
Welcome to SO. Hoora for finishing the tour and nice question and shown error code (tip: try using ">" and you get yourself a yellow box as background for the trackback). No further comments from review side. Enjoy SO ;-) - ZF007

2 Answers

0
votes

That error is generally due to the fact that your host name cannot be determined. This post may be of help: https://osric.com/chris/accidental-developer/2015/10/connecting-to-oracle-instance-in-aws-rds/

0
votes

I ran into this same issue and found that the HOSTALIASES mechanism requires working DNS. If your Lambda function is VPC attached, you must allow outbound DNS to either Amazon VPC DNS or your own internal DNS server if you have one.