-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_ssh.py
More file actions
43 lines (34 loc) · 1.07 KB
/
handler_ssh.py
File metadata and controls
43 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import boto3
import time
import datetime
import paramiko
import os
def worker_handler(event, context):
s3_client = boto3.client('s3')
# ec = boto3.client('ec2')
#Download private key file from secure S3 bucket
s3_client.download_file('ggs-gitlab-conf','delta-gg.pem','/tmp/delta.pem')
k = paramiko.RSAKey.from_private_key_file("/tmp/delta.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host='10.200.71.28'
print "Connecting to " + host
c.connect( hostname = host, username = "ec2-user", pkey = k )
print "Connected to " + host
commands = [
"df -h"
]
for command in commands:
print "Executing {}".format(command)
stdin , stdout, stderr = c.exec_command(command)
print stdout.read()
print stderr.read()
return
{
'message' : "Script execution completed. See Cloudwatch logs for complete output"
}
def lambda_handler(event, context):
worker_handler()
return 'successful'
if __name__ == '__main__':
worker_handler([], [])