7

I'm working on a simple script to connect my sftp server from aws-lambda and I'm getting

Unable to import module 'lambda_function': No module named '_cffi_backend'

when I import pysftp from aws-lambda. I'm using python3.6 and only import pysftp nothing more

I already try to install cffi

python3 pip install cffi
Daniel I. Cruz
  • 1,235
  • 1
  • 12
  • 13

4 Answers4

9

I've faced with the same issue on python 3.7 (cffi==1.11.2, cryptography==2.1.2, paramiko==2.3.1) and resolved it downgrading to python 3.6.

Found the solution in this issue topic.

enoted
  • 577
  • 7
  • 21
  • 2
    This fixed my issue. I was using Python 3.8 when my cffi was compiled for 3.6. You can tell which version of Python your cffi file has been compiled for in its name (for example `_cffi_backend.cpython-36m-x86_64-linux-gnu.so`). You can downgrade to Python 3.6 on the lambda console (for example https://.console.aws.amazon.com/lambda/home?region=#/functions). – lsusr Feb 08 '21 at 23:25
  • Thanks for this comment, I spent half day, trying different versions of lamdalayer. – NMAK Jul 02 '21 at 09:19
  • 1
    My problem was _cffi_backend for python 3.9. I had to back my lambdas down to 3.8 and use AWS method for making a layer. https://aws.amazon.com/premiumsupport/knowledge-center/lambda-import-module-error-python/ – Patrick Scott Best Apr 22 '22 at 23:23
4

This worked for me, and it was an easy fix. Maybe it could help someone else.

After trying -
pip3 -vvv install --upgrade --force-reinstall cffi

pip install cffi

I got the following module _cffi_backend.cp39-win_amd64.pyd from a working environment and placed it inside the site-packages of the missing location with the issue.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 19 '22 at 08:52
1

You need to include the third party modules in the Lambda package. Go to the directory where pip keeps the data for your modules, find the modules you're using, copy their directories and include in the Lambda zip file. Then deploy again on Lambda and run it. Should work.

Renato Byrro
  • 3,578
  • 19
  • 34
-2

You need to upload the dependencies to the lambda function. All you need to do is create a folder, lets call it 'test' and put your python code in it. Then, install the required python packages into the same folder. You can do it using the following command:

pip install --target <path directory> <package name>

This installs the required packages into the specified directory. In your case, the command will be

pip install --target C:\test requests

Repakula Srushith
  • 444
  • 1
  • 3
  • 10