· 5 years ago · Jul 08, 2020, 12:04 AM
1def postprocess_template(template):
2 """Foreach lambda, strip the Code nodes and add the api gateway nodes"
3
4 Args:
5 template (dict): The template to postprocess
6 """
7 print("Provided template's resources")
8 new_template = json.loads(template)
9
10 events_template = {
11 "Events": {
12 "ProxyResource": {
13 "Type": "Api",
14 "Properties": {
15 "Path": "",
16 "Method": ""
17 }
18 }
19 }
20 }
21
22 lambdaValues = {
23 "GetOrganizations": {
24 "Path": "/organizations",
25 "Method": "GET"
26 },
27 "GetAccounts": {
28 "Path": "/accounts",
29 "Method": "GET"
30 },
31 "GetToken": {
32 "Path": "/authenticate",
33 "Method": "POST"
34 },
35 "GetSites": {
36 "Path": "/sites",
37 "Method": "GET"
38 },
39 "CreateSites": {
40 "Path": "/sites/",
41 "Method": "POST"
42 },
43 "UpdateSites": {
44 "Path": "/sites/update",
45 "Method": "PATCH"
46 },
47 "DeleteSites": {
48 "Path": "/sites",
49 "Method": "DELETE"
50 },
51 #todo: REMOVE UNDELETE FROM THE API
52 "UndeleteSites": {
53 "Path": "/sites/undelete",
54 "Method": "POST"
55 },
56 "PutSites": {
57 "Path": "/sites",
58 "Method": "PUT"
59 }
60 }
61
62 for key, value in lambdaValues.items():
63 print("Beginning post-processing for " + key)
64 print(value)
65 # Fill in unique details of events node
66 event = events_template
67 print (event)
68 print (events_template)
69 event["Events"]["ProxyResource"]["Properties"]["Path"] = value["Path"]
70 event["Events"]["ProxyResource"]["Properties"]["Method"] = value["Method"]
71 # print(event)
72
73 # Delete the code node
74 print("Deleting code node for " + key)
75 del new_template["Resources"][key]["Properties"]["Code"]
76
77 print("Adding event node for " + key)
78 new_template["Resources"][key]["Properties"].update(event)
79 new_template["Resources"][key]["Type"] = "AWS::Serverless::Function"
80 print()
81
82 return json.dumps(new_template)