连接到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
中将libaio.so.1.0.1
的符号链接创建为libaio.so
- 使用在
~/lambda
中安装的 - 在
~lambda
中的
zip
文件
cx_Oracle
点子
index.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 *
将其压缩
- 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
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屋!