AWS Python Lambda with Oracle - OID Generation Failed even after adding HOSTALIASES

蹲街弑〆低调 提交于 2019-12-11 17:17:41

问题


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:


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/




回答2:


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.



来源:https://stackoverflow.com/questions/48177408/aws-python-lambda-with-oracle-oid-generation-failed-even-after-adding-hostalia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!