[feat] use json dumped dict response instead than JSONResponse
Browse files- src/app.py +16 -14
src/app.py
CHANGED
@@ -12,11 +12,6 @@ from src.utilities.utilities import base64_decode
|
|
12 |
logger = Logger()
|
13 |
|
14 |
|
15 |
-
class JSONResponse(Response):
|
16 |
-
def response_to_json(self):
|
17 |
-
return json.dumps(self.__dict__)
|
18 |
-
|
19 |
-
|
20 |
class BBoxWithPointInput(BaseModel):
|
21 |
bbox: input_floatlist
|
22 |
points: input_floatlist2
|
@@ -46,18 +41,25 @@ def get_response(status: int, start_time: float, request_id: str, output: BBoxWi
|
|
46 |
output.message = messages[status]
|
47 |
output.request_id = request_id
|
48 |
body = output.model_dump_json()
|
49 |
-
response =
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
54 |
logger.info(f"response type:{type(response)} => {response}.")
|
55 |
-
return
|
56 |
|
57 |
|
58 |
def lambda_handler(event: dict, context: LambdaContext):
|
59 |
logger.info(f"start with aws_request_id:{context.aws_request_id}.")
|
60 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
61 |
try:
|
62 |
logger.info(f"event:{json.dumps(event)}...")
|
63 |
logger.info(f"context:{context}...")
|
@@ -71,9 +73,9 @@ def lambda_handler(event: dict, context: LambdaContext):
|
|
71 |
logger.info(f"body: {type(body)}, {body}...")
|
72 |
|
73 |
if isinstance(body, str):
|
74 |
-
|
75 |
-
logger.info(f"
|
76 |
-
body = json.loads(
|
77 |
|
78 |
logger.info(f"body:{body}...")
|
79 |
|
|
|
12 |
logger = Logger()
|
13 |
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
class BBoxWithPointInput(BaseModel):
|
16 |
bbox: input_floatlist
|
17 |
points: input_floatlist2
|
|
|
41 |
output.message = messages[status]
|
42 |
output.request_id = request_id
|
43 |
body = output.model_dump_json()
|
44 |
+
response = {
|
45 |
+
"statusCode": status,
|
46 |
+
"headers": {
|
47 |
+
"Content-Type": content_types.APPLICATION_JSON if status == 200 else content_types.TEXT_PLAIN
|
48 |
+
},
|
49 |
+
"body": body,
|
50 |
+
"isBase64Encoded": False
|
51 |
+
}
|
52 |
logger.info(f"response type:{type(response)} => {response}.")
|
53 |
+
return json.dumps(response)
|
54 |
|
55 |
|
56 |
def lambda_handler(event: dict, context: LambdaContext):
|
57 |
logger.info(f"start with aws_request_id:{context.aws_request_id}.")
|
58 |
start_time = time.time()
|
59 |
+
|
60 |
+
if "version" in event:
|
61 |
+
logger.info(f"event version: {event['version']}.")
|
62 |
+
|
63 |
try:
|
64 |
logger.info(f"event:{json.dumps(event)}...")
|
65 |
logger.info(f"context:{context}...")
|
|
|
73 |
logger.info(f"body: {type(body)}, {body}...")
|
74 |
|
75 |
if isinstance(body, str):
|
76 |
+
body_decoded_str = base64_decode(body)
|
77 |
+
logger.info(f"body_decoded_str: {type(body_decoded_str)}, {body_decoded_str}...")
|
78 |
+
body = json.loads(body_decoded_str)
|
79 |
|
80 |
logger.info(f"body:{body}...")
|
81 |
|