【发布时间】:2018-01-01 06:42:37
【问题描述】:
我编写了一个简单的 python 脚本,它将通过 ssh 连接到 EC2 实例并在该实例中运行脚本。
我使用 paramiko 库进行 ssh 连接。下面是我的代码 sn-p。
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 文件夹。
【问题讨论】:
标签: python-3.x amazon-ec2 ssh aws-lambda paramiko