How to fix import error "No module named '_cffi_backend' " when import pysftp from aws-lambda

Question:

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
Asked By: Daniel I. Cruz

||

Answers:

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.

Answered By: Renato Byrro

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

Answered By: Repakula Srushith

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.

Answered By: enoted

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.

Answered By: Adeyemi Adenuga