【发布时间】:2020-05-02 23:24:34
【问题描述】:
我正在尝试使用 cx_Oracle 从 AWS Lambda 函数 (python3.7) 内部连接到 RDS(Oracle) 数据库。此外,Lambda 函数本身是使用 buildspec.yml 文件从 AWS CodeBuild 自动构建的。 CodeBuild 本身通过配置 AWS CodePipeline 运行,这样每当我放入代码的存储库(在本例中为 AWS CodeCommit)更新时,它就会自动构建内容。
我做过的事情: 1.我有一个AWS Lambda函数,代码如下。
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
- 在 buildspec.yml 我有以下构建命令。
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>
-
- 我还配置了Lambda函数的template.yml如下
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"
任何帮助将不胜感激。
【问题讨论】:
标签: aws-lambda cx-oracle aws-codebuild