PKV
PKV

Reputation: 177

Unable to use python library : 'paramiko' with AWS Lambda

I'm trying to transfer a file to a remote server and for that I'm using paramiko library. I'm able to successfully transfer the file to a remote server by running the python script locally. The script I'm using is below:

import paramiko
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='my-host-name',username='myid',password='mypwd')
sftp_client=ssh.open_sftp()
#passing localpath, remotepath
sftp_client.put(r'C:\Users\test.csv', r'/dev/data/team/test.csv')
sftp_client.close()
ssh.close()

I need to run this script on AWS Lambda. However, when I'm running this script on AWS Lambda, it's giving me the following error.

enter image description here

As per Paramiko documentation, it has few direct dependencies and bcrypt is one of them.

I have created a Lambda Layer by uploading the zip file with all the relevant modules (did pip install paramiko -t .) and have also followed the folder structure as per python3.7 requirement (python/lib/python3.7/site-packages/)

I did a lot of research online, but did not find a solution that could fix the issue.

Please help me!

Upvotes: 2

Views: 4049

Answers (1)

Ahmed Hammad
Ahmed Hammad

Reputation: 3095

There are typically two reasons for this:

Either that you haven't named the handler name correctly, in this case go to Lambda -> Functions -> Your Function -> Configuration and check that the value in the handler field is the right one.

Or that one of the dependencies that you included in the zipped file is compiled to your machines's architecture, which is typically different from the one that's hosting the lambda function. In this case you should find out what Linux version is hosting you lambda function, and get a pre-compiled version that can be used by AWS lambda.

Upvotes: 4

Related Questions