kundan kaushik
kundan kaushik

Reputation: 215

Pysftp package is not working in lambda function throwing error : cannot import name '_bcrypt' from 'bcrypt' (./lib/bcrypt/__init__.py)

I download (pip install pysftp) and make a zip file and upload in a lambda function. but it is not working in a lambda function. throwing error.

Response:

{
  "errorMessage": "Unable to import module 'lambda_function': cannot import name '_bcrypt' from 'bcrypt' (./lib/bcrypt/__init__.py)",
  "errorType": "Runtime.ImportModuleError"
}

Many thank you in advance.

Upvotes: 0

Views: 1886

Answers (4)

Ethan Nguyen
Ethan Nguyen

Reputation: 114

To install everything in the same directory, use the below command

pip install pysftp -t .

After that, zip the entire dir & upload to Lambda console. Little old trick that helpssfor those who using Lambda for the 1st time...

Upvotes: 1

Joshua Francis
Joshua Francis

Reputation: 63

The operation "pip install pysftp" is to be performed in a linux distribution for preparing the lib for aws lambda. I had used ubuntu in docker on windows to perform pip install on mounted volume to generate the lib.

Upvotes: 1

Rich Andrews
Rich Andrews

Reputation: 1670

Since you need to troubleshoot module dependencies, the python runtime environment of AWS Lambda must be inspected.

In your AWS Lambda, print the modules that are loaded, and therefore available to the other modules that your code imports.

def lambda_handler(event, context):
    print (help("modules"))

Running this in a python interpreter is illuminating.

python
help("modules")

You will see Please wait a moment while I gather a list of all available modules... and then a big list of available modules that are importable.

You will find that you are missing bcrypt, for within that module as taught by help(bcrypt) you will find the missing dependency _bcrypt.

Should bcrypt be available to the lambda or just a python interpreter, it is found in this manner.

>>> bcrypt._bcrypt
<module 'bcrypt._bcrypt' from '/usr/local/lib/python2.7/site-packages/bcrypt/_bcrypt.so'>

Upvotes: 1

Dhinakar Babu
Dhinakar Babu

Reputation: 11

Try reinstalling the packages and uploading the new packages. If it still shows error, move your development environment from Windows to Linux. Similar kind of error for your reference: [1]: https://forums.aws.amazon.com/thread.jspa?messageID=804753&tstart=0

Upvotes: 1

Related Questions