-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboilerplate.py
47 lines (36 loc) · 976 Bytes
/
boilerplate.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
import json
from typing import Tuple
payload_keys = [
"key1",
"key2",
]
def test_function(*args, **kwargs) -> Tuple[int, str, dict]:
result = {}
return 200, "Success", result
def lambda_handler(event, context):
body = json.loads(event["body"])
for key in payload_keys:
if key not in body:
return {
"statusCode": 400,
"body": json.dumps(
{
"message": f"Missing key: {key}",
}
),
}
status_code, message, result = test_function(**body)
return {
"statusCode": status_code,
"body": json.dumps({"message": message, "data": result}, ensure_ascii=False),
}
if __name__ == "__main__":
event = {
"body": json.dumps(
{
"key1": "value1",
"key2": "value2",
}
)
}
print(lambda_handler(event, None))