带有Oracle的AWS Python Lambda-即使添加HOSTALIASES,OID生成也会失败 [英] AWS Python Lambda with Oracle - OID Generation Failed even after adding HOSTALIASES

查看:143
本文介绍了带有Oracle的AWS Python Lambda-即使添加HOSTALIASES,OID生成也会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 lambda python 使用 cx_oracle软件包连接到 rds 上的 oracle 但我得到:

I am trying to connect to oracle on rds using lambda with python using cx_oracle package but i get:

ORA-21561:OID生成失败:DatabaseError.

ORA-21561: OID generation failed: DatabaseError.

即使添加了带有 lambda-server-name localhost的文件/tmp/HOSTALIASES .还为 lambda环境变量添加了HOSTALIASES.引用自:带有Oracle的AWS Python Lambda-OID生成失败

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.

如何解决 aws lambda

这是我的代码

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()

输出:

ORA-21561:OID生成失败:DatabaseError跟踪(最新) 最后一次调用):文件"/var/task/orcl_fetch_function.py",第25行,在 orcl_fetch_records conn = cx_Oracle.connect(用户名",密码", dsn)DatabaseError:ORA-21561:OID生成失败

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

推荐答案

我遇到了同样的问题,发现HOSTALIASES机制需要有效的DNS.如果您的Lambda功能已附加VPC,则必须允许出站DNS到Amazon VPC DNS或您自己的内部DNS服务器(如果有的话).

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.

这篇关于带有Oracle的AWS Python Lambda-即使添加HOSTALIASES,OID生成也会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆