AWS lambda 无法导入名称“_bcrypt”
AWS lambda cannot import name '_bcrypt'
我已经编写了一个简单的 python 脚本,它将通过 ssh 连接到一个 EC2 实例,并 运行 该实例中的一个脚本。
我使用 paramiko 库来执行 ssh connect.Below 是我的代码片段。
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 文件夹。
我猜你的本地电脑不是 linux 电脑。
您需要在 linux PC 上构建部署包。下面的 Lambda 运行基于 linux.
的 AMI 映像
我已经在我自己的博客上记录了这个 here
我已经编写了一个简单的 python 脚本,它将通过 ssh 连接到一个 EC2 实例,并 运行 该实例中的一个脚本。
我使用 paramiko 库来执行 ssh connect.Below 是我的代码片段。
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 文件夹。
我猜你的本地电脑不是 linux 电脑。
您需要在 linux PC 上构建部署包。下面的 Lambda 运行基于 linux.
的 AMI 映像我已经在我自己的博客上记录了这个 here