-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (46 loc) · 1.41 KB
/
app.py
File metadata and controls
53 lines (46 loc) · 1.41 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
44
45
46
47
48
49
50
51
52
53
"""
The app module implements lambda handler function.
"""
import json
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def handler(event, _):
"""
Handles the incoming event and context from AWS Lambda.
:param event: The event dict from AWS Lambda.
:param context: The context object from AWS Lambda.
:return: A dict containing the statusCode, event, body, and path.
"""
try:
success = False
message = "Test message"
body = {"message": str(message)}
logger.info("result: \n %s ", json.dumps(body))
response = {
"statusCode": 200,
"event": json.dumps(event),
"body": json.dumps(body),
"path": "app.py",
}
if not success:
logger.error("result: \n %s ", json.dumps(body))
response = {
"statusCode": 500,
"event": json.dumps(event),
"body": json.dumps(body),
"path": "app.py",
}
return response
# pylint: disable=broad-except
except Exception as ex:
logger.error("error occured: \n %s ", ex)
response = {
"statusCode": 500,
"event": json.dumps(event),
"body": json.dumps({"error": str(ex)}),
"path": "app.py",
}
return response
if __name__ == "__main__":
handler(None, None)