连接到 Oracle RDS [英] Connecting to 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)
- 下载了 Instantclient-basic-linux.x64-12.2.0.1.0.zip 和
Instantclient-sdk-linux.x64-12.2.0.1.0.zip - 创建此文件夹结构
~/lambda/lib/
- 解压
~/lambda/lib/
中的 - 将
libaio.so.1.0.1
从/lib64/
复制到~/lambda/lib/
- 在
~/lambda
中创建 - 在
~/lambda
中使用安装了 - 写在
~lambda
中的
zip
文件libaio.so.1.0.1
的符号链接为libaio.so
cx_Oracle
的pipindex.py
脚本下面- Downloaded the instantclient-basic-linux.x64-12.2.0.1.0.zip and
instantclient-sdk-linux.x64-12.2.0.1.0.zip - Created this folder structure
~/lambda/lib/
- Extracted the
zip
files in the~/lambda/lib/
- copied the
libaio.so.1.0.1
from/lib64/
into~/lambda/lib/
- Created symbolic link of
libaio.so.1.0.1
aslibaio.so
in~/lambda
- using pip installed
cx_Oracle
in~/lambda
- 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}
`
- 然后使用
zip -r9 ~/upload.zip *
压缩它
在 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
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屋!