连接到 Oracle RDS [英] Connecting to Oracle RDS

查看:37
本文介绍了连接到 Oracle RDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AWS lambda 和 python 连接到 Oracle.

I am trying to connect to Oracle using AWS lambda and python.

这些是我遵循的步骤.(EC2实例都做完了)

These are the step I followed. (Everything has done EC2 instance)

  1. 下载了 Instantclient-basic-linux.x64-12.2.0.1.0.zip 和
    Instantclient-sdk-linux.x64-12.2.0.1.0.zip
  2. 创建此文件夹结构~/lambda/lib/
  3. 解压~/lambda/lib/
  4. 中的zip文件
  5. libaio.so.1.0.1/lib64/复制到~/lambda/lib/
  6. ~/lambda
  7. 中创建libaio.so.1.0.1的符号链接为libaio.so
  8. ~/lambda
  9. 中使用安装了cx_Oracle的pip
  10. 写在~lambda
  11. 中的index.py脚本下面
  1. Downloaded the instantclient-basic-linux.x64-12.2.0.1.0.zip and
    instantclient-sdk-linux.x64-12.2.0.1.0.zip
  2. Created this folder structure ~/lambda/lib/
  3. Extracted the zip files in the ~/lambda/lib/
  4. copied the libaio.so.1.0.1 from /lib64/ into ~/lambda/lib/
  5. Created symbolic link of libaio.so.1.0.1 as libaio.so in ~/lambda
  6. using pip installed cx_Oracle in ~/lambda
  7. written below index.py script in ~lambda

`

import cx_Oracle

def handler(event, context):
    message = ""
    cursor = None
    connection = None    
    try:
        connection = cx_Oracle.connect("USERNAME", "PASSWORD", "DOMAIN/orcl")
        cursor = connection.cursor()
        cursor.execute("""QUERY""")
    except Exception as e:
        message += " {Error in connection} " + str(e)
    finally:
        if cursor:
            cursor.close()
        if connection:
            connection.close()
    return {'message' : message}

`

  1. 然后使用 zip -r9 ~/upload.zip *
  2. 压缩它

在 AWS lambda 上运行代码后,出现以下错误.

After running the code on AWS lambda it gives the following error.

尝试检索 ORA-01804 错误文本时出错

我尝试设置 ENV ORACLE_HOME=/var/task 和/var/task/lib 但没有奏效

I tried setting ENV ORACLE_HOME=/var/task and /var/task/lib but did not worked

我看了下面的答案,但还没有找到帮助

I looked below answers but did not find help yet

尝试检索错误 ORA 的文本时出错-01019

Oracle使用 node-oracle:尝试检索错误 ORA-01804 的文本时出错

推荐答案

我通过简单地使用符号链接正确压缩文件来解决这个问题

I solved this by simply zipping the files properly with the symbolic links

首先我创建了三个符号链接(相对于上面的目录结构):

First I created three symbolic links (with respect to above dir structure):

ln -s ./lib/libaio.so.1.0.1 ./lib/libaio.so.1

ln -s ./lib/libaio.so.1.0.1 ./lib/libaio.so

ln -s ./lib/libaio.so.1.0.1 ./libaio.so.1.0.1

ln -s ./lib/libclntsh.so.12.1 ./lib/libclntsh.so

然后我错误地压缩了它,我是这样做的:

then i was zipping it incorretly I did it like this:

zip --symlinks -r9 ~/lamda.zip *

成功了!那么正确.希望它可以帮助某人.

it worked! properly then.Hope it helps somebody.

这篇关于连接到 Oracle RDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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