【问题标题】:cx_Oracle problem in AWS Lambda built using AWS CodeBuild使用 AWS CodeBuild 构建的 AWS Lambda 中的 cx_Oracle 问题
【发布时间】: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
  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】:

    当您想使用 cx_Oracle 访问您的 oracle 数据库时,在压缩 lambda 包(代码和其他依赖项)时,请确保保留符号链接

    zip --symlinks -r lambda.zip .
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 2022-11-19
      • 2019-03-26
      • 2019-02-15
      相关资源
      最近更新 更多