[使用AWS CodeBuild构建的AWS Lambda中的cx_Oracle问题

问题描述 投票:0回答:1

我正在尝试使用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
  1. 在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>
        -  
  1. 我还如下配置了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
1个回答
0
投票

[enter image description here当您想使用cx_Oracle来访问oracle数据库时,在压缩lambda软件包(代码和其他依赖项)的那一刻,请确保保留符号链接

zip --symlinks -r lambda.zip .

我还没有使用codebuild,但是我已经在Linux服务器中构建了lambda包,很快我将在Azure Devops中创建一个构建管道。

© www.soinside.com 2019 - 2024. All rights reserved.