无法使用 python 库:“paramiko"与 AWS Lambda [英] Unable to use python library : 'paramiko' with AWS Lambda

查看:73
本文介绍了无法使用 python 库:“paramiko"与 AWS Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件传输到远程服务器,为此我使用了 paramiko 库.通过在本地运行 python 脚本,我能够成功地将文件传输到远程服务器.我正在使用的脚本如下:

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()

我需要在 AWS Lambda 上运行这个脚本.但是,当我在 AWS Lambda 上运行此脚本时,出现以下错误.

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.

根据 Paramiko 文档,它几乎没有直接依赖项,bcrypt 就是其中之一.

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

我通过上传包含所有相关模块的 zip 文件(did pip install paramiko -t .)创建了一个 Lambda 层,并且还按照 python3.7 要求(python/lib/python3.7/站点包/)

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.

请帮帮我!

推荐答案

通常有两个原因:

或者你没有正确命名处理程序名称,在这种情况下转到 Lambda ->功能 ->你的功能 ->配置并检查处理程序字段中的值是否正确.

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.

或者您在压缩文件中包含的依赖项之一被编译为您机器的架构,这通常与托管 lambda 函数的架构不同.在这种情况下,您应该找出托管您的 lambda 函数的 Linux 版本,并获得一个可供 AWS lambda 使用的预编译版本.

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.

这篇关于无法使用 python 库:“paramiko"与 AWS Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆