-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (32 loc) · 1.11 KB
/
main.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
import sys
import json
from handler import *
def modifyPayload(payload):
'''Transform and return payload.'''
#payload = **YOUR TRANSFORMATION HERE**
#print(payload) -> add a print statement if you want to
#review the payload before/after modification in CloudWatch logs.
return payload
def filterLogic(payload, drop_record=False):
'''Drop record if logic returns True.'''
#drop_record = **YOUR LOGIC HERE** (must return a boolean)
return drop_record
def test_lambda():
'''
Read json file, apply transformation, and print and save
output without encoding payload back to base64.
'''
try:
fname = sys.argv[1]
except:
print("Handler test mode. Usage: "
"'python3 main.py <sample json file name>'")
return
myEvent = updateDict(getFirehoseEvent(), 'records',
prepareSampleRecords(getJsonSamples(fname))
)
output = decodeOutputPayloads(lambda_handler(myEvent, ''))
saveOutputJson(output)
print(json.dumps(output, indent=3, sort_keys=True))
if __name__ == '__main__':
test_lambda()