AWS Lambda错误:无法导入模块"function_name":没有名为"module._module"的模块 [英] AWS Lambda Error: Unable to import module 'function_name': No module named 'module._module'

查看:66
本文介绍了AWS Lambda错误:无法导入模块"function_name":没有名为"module._module"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用包 impyla 的AWS Lambda上部署python脚本,该包依赖于包 bitarray .

I am deploying a python script on AWS Lambda which uses the package impyla which has a dependency on the package bitarray.

from impala.dbapi import connect

我的python文件称为 authorize_ingress.py ,它具有名为 handle_authorize_ingress(event,context)的功能,该功能已正确配置.请参见下面的屏幕截图:

My python file is called authorize_ingress.py which has a function called handle_authorize_ingress(event, context) which are properly configured. See the screenshots below:

我函数的文件:

在lambda中指定的处理程序:

The handler in lambda specified:

代码本身中的处理程序:

The handler in code itself:

我的zip文件的所有内容都在根目录中(而不是嵌套在目录中):

and my zip file has everything in the root (and not nested within a directory):

bitarray 软件包由 impyla 自动安装:

每一次,我都会收到以下答复:

Every single time, I am met with this response:

到目前为止,我已经尝试:

As of now, I have tried to:

  • 该软件包是使用 zip -r 选项生成的.
  • 文件位于zip的根目录中,而不是嵌套在目录中.
  • 该功能在本地可以很好地工作.
  • 我已经尝试过 virtualenv 并只是将依赖项安装在 packages/路径中,但是没有运气
  • The package was generated with zip -r option.
  • The files are in the root of the zip and not nested within a directory.
  • The function works perfectly fine locally.
  • I have tried both virtualenv and simply installing the dependencies in a packages/ path but no luck

有什么主意我可能做错了吗?我按照 AWS Lambda部署指南.任何帮助将不胜感激,谢谢!

Any ideas what I might be doing wrong? I generated my deployment package following AWS' Lambda Deployment Guide. Any help would be appreciated, thank you!

推荐答案

在这里.您可以通过此gdrive 链接下载此lambda层..该层与Python 3.8兼容,因此请确保选择正确的lambda运行时.

Here you go. You can download this lambda layer through this gdrive link. This layer is compatible with Python 3.8, so make sure you select the correct lambda runtime.

如果您想知道我是如何生成此lambda层的,那么这里列出了我的基本操作:

If you are curious to know how I generated this lambda layer, here is a list of basically what I did:

  • 无服务器框架
  • serverless-python-requirements插件
  • docker
  • serverless.yml
service: serverless-example

provider:
  name: aws
  runtime: python3.8
  region: us-east-1
  profile: dummy

functions:
  dummy:
    handler: dummy.handler

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: non-linux
    layer: true

  • requirements.txt
  • impyla==0.16.2
    

    然后只需执行 sls软件包-p pkg .一分钟后,名为 pythonRequirements.zip 的层将准备就绪,位于 .serverless 目录下.

    Then simply do sls package -p pkg. The layer named pythonRequirements.zip will be ready in a minute under .serverless directory.

    这篇关于AWS Lambda错误:无法导入模块"function_name":没有名为"module._module"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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