-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
48 lines (42 loc) · 1.12 KB
/
server.py
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
44
45
46
47
48
import os
import sys
import time
import json
import dockerInterface
class environment:
zip = ""
name = ""
image = ""
input_json = ""
maintainer = ""
cmd = ""
def __init__(self, zip, name, input_json, image, cmd):
self.zip = zip
self.name = name
self.image = image
self.input_json = input_json
self.maintainer = os.popen('whoami').read()
self.cmd = cmd
def setup(zipFile, input_json):
if "/" in zipFile:
print("ZipFile in local filesystem")
if os.path.exists(zipFile) == False:
print("ZipFile not found. Exiting...")
sys.exit()
invokeContainer(zipFile, input_json)
else:
print("ZipFile in S3 Store")
invokeLambda(zipFile, input_json)
def getCmd(video):
return "python handler.py " + video
def invokeContainer(zipFile, input_json):
print("Invoking Docker Container")
j = json.loads(input_json)
name = j['lambda_name']
video = j['key']
image = "ubuntu:14.04"
cmd = getCmd(video)
env = environment(zipFile, name, input_json, image, cmd)
dockerInterface.apiCreateContainer(env)
def invokeLambda(zipFile, input_json):
print("Invoking AWS Lambda")