我编写了一个简单的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) 我试图阻止页面的某些部分.我正在关注http://jquery.malsup.com/block/#element教程,但我无法映射该元素.
我的js:
$('div.repoDisplay').blockUI({ message: '' ,overlayCSS: { backgroundColor: '#fff' }});
Run Code Online (Sandbox Code Playgroud)
我的HTML:
<div class="container-sc" style="display: table;">
<div id='repoDisplay' >
<div style="display: table-cell;width:150px">
\\\\\\\\\\\
</div>
</div>
<div style="display: table-cell;padding:10px;width:85%"">
{{outlet}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
但它显示未捕获的类型错误:在我的js中未定义.
谢谢您的帮助
amazon-ec2 ×1
aws-lambda ×1
blockui ×1
javascript ×1
jquery ×1
paramiko ×1
python-3.x ×1
ssh ×1