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

查看:83
本文介绍了连接到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中将libaio.so.1.0.1的符号链接创建为libaio.so
  7. 使用在~/lambda
  8. 中安装的cx_Oracle点子
  9. ~lambda
  10. 中的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. 将其压缩
  1. Then zipped it using zip -r9 ~/upload.zip *

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

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

Error while trying to retrieve text for 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天全站免登陆