0

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

1
  • 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 ;-) Commented Jan 9, 2018 at 22:29

2 Answers 2

0

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/

Sign up to request clarification or add additional context in comments.

4 Comments

In AWS Lambda I don't have write access to etc/hosts file. So i have set the hosts by adding HOSTALIASES file and setting the values in HOSTALIASES file as "host-name localhost" . I have also tried the format from the URL you have given "127.0.0.1 host-name localhost". It still throws same OID generation error.
Is the client the same as the server? Or are you using different machines?
I trying to connect to rds oracle DB on same aws vpc which lambda function is executing.
So what is the value of your /tmp/HOSTALIASES? And the value of the environment variable HOSTALIASES? Everything I've seen suggests this should work. What version of cx_Oracle are you using?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.