python-3.x - AWS lambda 无法导入名称 '_bcrypt'

标签 python-3.x amazon-ec2 ssh aws-lambda paramiko

我编写了一个简单的 python 脚本,它将通过 ssh 连接到 EC2 实例并在该实例中运行脚本。

我使用 paramiko 库来做 ssh 连接。下面是我的代码片段。

def lambda_handler(event, context):
    client = boto3.client('ec2')
    s3_client = boto3.client('s3')
    # Download private key file from secure S3 bucket
    s3_client.download_file('test','test.pem', '/tmp/test.pem')
    k = paramiko.RSAKey.from_private_key_file("/tmp/test.pem")
    c = paramiko.SSHClient()
    c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    bastion_host = "xxx.com"
    print ("Connecting to " + bastion_host)
    c.connect(hostname=bastion_host, username="yyy", key_filename="/tmp/test.pem")
    print ("Connected to " + bastion_host)
    commands = [

        "sh /home/ec2-user/TestDeploy.sh"
    ]
    for command in commands:
        print ("Executing {}".format(command))
        stdin, stdout, stderr = c.exec_command(command)
        print (stdout.read())
        print (stderr.read())
return 'Hello from Lambda'

在我的本地设置中,python 版本为 3.6.2,它工作正常。但是当我将它与 AWS lambda 中的所有依赖库一起上传并运行时,它给了我以下错误。
cannot import name '_bcrypt'

我已经验证我在上传的 zip 中有 bcrypt 文件夹。

最佳答案

我猜您的本地 PC 不是 Linux PC。

您需要在 Linux PC 上构建部署包。 Lambda 下面运行 AMI 镜像,它是基于 linux 的。

我已经在我自己的博客上记录了这一点 here

关于python-3.x - AWS lambda 无法导入名称 '_bcrypt',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45318539/

相关文章:

linux - AWS 弹性 beanstalk ec2 服务器上的 node.js 命令

amazon-web-services - 如何在实例创建时将文件夹从 S3 复制到弹性 beantalk 实例

python - 无法在 Windows XP Professional 中安装 Python 3.5

python - 在Python中从md5读取哈希值

python - pip(python2)和pip3(python3)可以共存吗?

git - 无法覆盖 C :\Program Files\Git\etc\ssh

command-line - 在ssh模式下下载文件?

python - 在字典理解中使用 locals()

amazon-web-services - 如何使用代理协议(protocol)版本 2 通过 AWS Network Load Balancer 获取客户端的真实 IP 地址?

linux - 在远程系统上复制文件