模块初始化错误:无法在AWS Lambda上加载本机模块'Crypto.Cipher._raw_ecb' [英] module initialization error: Cannot load native module 'Crypto.Cipher._raw_ecb' at AWS lambda

查看:962
本文介绍了模块初始化错误:无法在AWS Lambda上加载本机模块'Crypto.Cipher._raw_ecb'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS Lambda进行服务.我正在使用PyCryptodome进行加密和解密.我可以在本地测试我的应用程序,但是当我上传到AWS lambda进行解密时.我收到错误信息

I am making service using AWS lambda. I am using PyCryptodome for encryption and decryption. I am able to test my application locally, but when I upload to AWS lambda for decrypting. I get the error as

模块初始化错误:无法加载本机模块'Crypto.Cipher._raw_ecb':尝试'_raw_ecb.cpython-36m-x86_64-linux-gnu.so':/var/task/Cryptodome/Util/../Cipher/_raw_ecb.cpython-36m-x86_64-linux-gnu.so:无法打开共享对象文件:无此类文件或目录,尝试"_raw_ecb.abi3.so":/var/task/Cryptodome/Util/../Cipher/_raw_ecb .abi3.so:无法打开共享对象文件:没有此类文件或目录,尝试"_raw_ecb.so":/var/task/Cryptodome/Util/../Cipher/_raw_ecb.so:无效的ELF标头

module initialization error: Cannot load native module 'Crypto.Cipher._raw_ecb': Trying '_raw_ecb.cpython-36m-x86_64-linux-gnu.so': /var/task/Cryptodome/Util/../Cipher/_raw_ecb.cpython-36m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory, Trying '_raw_ecb.abi3.so': /var/task/Cryptodome/Util/../Cipher/_raw_ecb.abi3.so: cannot open shared object file: No such file or directory, Trying '_raw_ecb.so': /var/task/Cryptodome/Util/../Cipher/_raw_ecb.so: invalid ELF header

我要解密的代码是

    def blowfish_decrypt(enc):
        secret_key = b"somestring"
        iv = b"somerandomiv"
        logger.info("in the decrypter")
        crypt_obj = bf_cbc.new(secret_key, bf_cbc.MODE_CBC, IV=iv)
        original = crypt_obj.decrypt(base64.b64decode(enc))
        original = original.decode("utf-8")
        logger.info("decrypted")
        return original

我正在关注资源: https://github.com/pyinstaller/pyinstaller/issues/2125 ,但这也无济于事.

I was following the resource: https://github.com/pyinstaller/pyinstaller/issues/2125, but this didn't help me either.

应用了指定的所有细节后,我得到了上述相同的错误.

after applying all the details as specified I am getting the same above error.

推荐答案

您的本地开发环境似乎与Lambda执行环境不兼容. PyCryptodome使用的本机库不能在这两种环境之间移植;重要的是,在哪个环境中pip安装了库.

It looks like your local dev environment is not compatible with the Lambda execution environment. The native libraries that PyCryptodome uses are not portable across these two environments; it matters in which env the library was pip installed.

一种修复方法是使用 Lambci 泊坞窗映像来构建库,然后添加它到zip文件.假设您已安装Docker,请

One way to fix it is to use Lambci docker image to build the library and then add it to the zip file. Assuming you have Docker installed, do

docker pull lambci/lambda:build-python3.6
docker run --rm -v `pwd`:/var/task lambci/lambda:build-python3.6 pip install pycryptodome -t pycryptodome

这将在docker环境中pip安装lib.命令完成后,您可以在pycryptodome本地目录中使用它.

This will pip install the lib in the docker environment. After the command finishes, you'll have it available in the pycryptodome local dir.

以更自动化/可重复的方式,查看 AWS SAM aws-sam-cli ,它为您提供了一些非常有用的命令来构建,打包和部署您的Lambda应用.

For a more automated/repeatable way, have a look at AWS SAM and aws-sam-cli which gives you some very useful commands to build, package and deploy your Lambda apps.

这篇关于模块初始化错误:无法在AWS Lambda上加载本机模块'Crypto.Cipher._raw_ecb'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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