将Python模块导入AWS Lambda [英] Import Python module into AWS Lambda

查看:440
本文介绍了将Python模块导入AWS Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照文档中的所有步骤操作:
https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

I have followed all the steps in the documentation: https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html


  1. 创建目录。

  1. create a directory.

将所有Python源文件(.py文件)保存在此目录的根目录下。

Save all of your Python source files (the .py files) at the root level of this directory.

在目录的根级别使用pip安装任何库。

Install any libraries using pip at the root level of the directory.

压缩project-dir目录的内容)

Zip the content of the project-dir directory)

但是我将zip文件上传到 lambda 函数后,出现错误消息我测试了脚本

But after I uploaded the zip-file to lambda function, I got the error message when I test the script

我的代码:

    import psycopg2
    #my code...

错误:

    Unable to import module 'myfilemane': No module named 'psycopg2._psycopg'

我不知道...的后缀'_ psycopg'在哪里...

I don't know where is the suffix '_psycopg' from...

对此有任何帮助吗?

推荐答案

我相信这是因为 psycopg2 需要使用用于Linux的静态链接库来编译。请参考使用psycopg2和Lambda来更新Redshift(Python),以获取有关此问题的更多详细信息。在OSX上编译 psycopg2 的问题的另一个[参考] [1]。

I believe this is caused because psycopg2 needs to be build an compiled with statically linked libraries for Linux. Please reference Using psycopg2 with Lambda to Update Redshift (Python) for more details on this issue. Another [reference][1] of problems of compiling psycopg2 on OSX.

有一些解决方案,但基本上归结为在Linux机器上安装该库并将其用作上传包中的Psycopg2库。

There are a few solutions, but basically it comes down to installing the library on a Linux machine and using that as the Psycopg2 Library in your upload package.

这篇关于将Python模块导入AWS Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆