简体   繁体   中英

My Python script using Paramiko runs perfectly in the IDE (PyCharm) and command line but doesn't run on AWS Lambda

I'm writing a Python script (Python version 3.7 on Mac OS 10.15.7) that I intend to put on our AWS Lambda server and the script uses Paramiko. It runs perfectly fine in my IDE and on the command line, but when I try to run it on Lambda, I get this error message:

{
  "errorMessage": "Unable to import module 'lambda_function': libs/bcrypt/_bcrypt.abi3.so: invalid ELF header",
  "errorType": "Runtime.ImportModuleError"
}

I found this similar-looking question on Stack Overflow, but the answers to that question don't seem to apply to this situation as they relate to Windows and to a different Python library. But maybe there's something I missed?

Edit: Something that may be relevant is that my computer has Python 3.9 installed but I'm trying to write this in Python 3.7.

我通过为 PySFTP/Paramiko 创建一个层来解决这个问题。

The reason this is happening is because when you ran "pip install paramiko" it installs it according to your OS and computer architecture. This may not be the same architecture as what your Lambda function is running on.

I would recommend following this guide to properly create layers to ship with Lambda functions: https://oznetnerd.com/2020/11/11/lambda-packaging-the-right-way/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM