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.

7
  • 1
    How did you bundle Paramiko with your lambda? Commented Nov 20, 2020 at 1: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. Commented Nov 20, 2020 at 1: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. Commented Nov 20, 2020 at 2:27
  • You have to create layer for it Commented Nov 20, 2020 at 2:36
  • @aviboy2006 Thank you. What does that entail? Commented Nov 20, 2020 at 3:04

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.