我试图使用cx_Oracle从AWS函数(python3.7)中连接到RDS(Oracle)数据库。此外,Lambda函数本身是由AWS CodeBuild使用buildspec.yml文件自动生成的。CodeBuild本身是通过配置AWS CodePipeline来运行的,每当我将代码放在其中的存储库(在本例中是AWS CodeCommit)被更新时,它就会自动构建这些内容。
我所做的事情: 1.我有一个AWS函数,其代码如下所示。
import cx_Oracle
def lambda_handler(event, context):
dsn = cx_Oracle.makedsn('www.host.com', '1521', 'dbname')
connection = cx_Oracle.connect(user='user', password='password', dsn=dsn)
cursor = connection.cursor()
cursor.execute('select * from table_name')
return cursor version: 0.2
phases:
install:
runtime-versions:
python: 3.7
commands:
- pip install cx_Oracle -t ./ # to install cx_Oracle package in the same directory as the script
- unzip instantclient-basic-linux*.zip -d /opt/oracle # I have downloaded the zip file beforehand
<other code>
- AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Making a test lambda function using codepipeline
Resources:
funcAuthorityReceive:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: testFunction
Environment:
Variables:
PATH: '/opt/oracle/instantclient_19_5:$PATH'
LD_LIBRARY_PATH : '$LD_LIBRARY_PATH:/opt/oracle/instantclient_19_5'
Handler: lambda_function.lambda_handler
MemorySize: 128
Role: 'arn:aws:iam::XXXXXXXXXXXXXX:role/role-for-lambda
Runtime: python3.7
CodeUri: ./在这里,一切运行顺利,Lambda函数本身也被构建,但是当我运行lambda时,会出现这样的错误:
"DPI-1047: Cannot locate a 64-bit Oracle Client library: \"libclntsh.so: cannot open shared object file: No such file or directory\". See https://oracle.github.io/odpi/doc/installation.html#linux for help"任何帮助都将不胜感激。
发布于 2020-01-16 10:40:20
当您想使用cx_Oracle到达oracle数据库时,在压缩lambda包(代码和其他依赖项)时,请确保保留符号链接。

zip --symlinks -r lambda.zip .我还没有使用代码构建,但是我已经在linux服务器中构建了lambda包,不久我将在Azure Devops中创建一个构建管道。
https://stackoverflow.com/questions/59764209
复制相似问题