AWS Lambda无法导入名称'_bcrypt'

Alt*_*haf 4 ssh amazon-ec2 paramiko python-3.x aws-lambda

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

我使用paramiko库进行ssh connect。下面是我的代码段。

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'
Run Code Online (Sandbox Code Playgroud)

在我的本地安装中,python版本为3.6.2,它工作正常。但是,当我将其与AWS lambda中的所有相关库一起上传并运行时,它给了我以下错误。

cannot import name '_bcrypt'
Run Code Online (Sandbox Code Playgroud)

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

Day*_*ayo 5

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

您需要在Linux PC上构建部署程序包。下面的Lambda运行基于Linux的AMI映像。

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