0

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.

  • 1
    How did you bundle `Paramiko` with your lambda? – Marcin Nov 20 '20 at 01:34
  • From my experience, linux usually throws an "invalid ELF header" when the operating system is missing a package, in the case of arch linux, binutils. As a side note, the question you've linked is examining a '.pyd' file, but a '.so' file is a valid ELF file, specifically a binary library meant to be linked at runtime. – Nolan Faught Nov 20 '20 at 01:43
  • @Marcin I got Paramiko onto Lambda by installing it in the directory my script is in and zipping the directory and uploading the zip to Lambda. – Walt Gottlieb Nov 20 '20 at 02:27
  • You have to create layer for it – Avinash Dalvi Nov 20 '20 at 02:36
  • @aviboy2006 Thank you. What does that entail? – Walt Gottlieb Nov 20 '20 at 03:04
  • get library package from your local and create AWS lambda layer. While editing lambda select respective layer version. If I am not wrong this package not supported by AWS Lambda. But can give try by this approach. – Avinash Dalvi Nov 20 '20 at 03:07
  • https://adhorn.medium.com/getting-started-with-aws-lambda-layers-for-python-6e10b1f9a5d – Avinash Dalvi Nov 20 '20 at 03:07

2 Answers2

1

I solved this by creating a layer for PySFTP/Paramiko.

0

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/

Prithvi Boinpally
  • 427
  • 1
  • 9
  • 23