File size: 1,852 Bytes
f2a79fa 3dbe011 43d87b3 c6054f0 85dd36a f2a79fa 7d6e00c 238719b fa76f5f 43d87b3 3dbe011 7d6e00c f2a79fa 6f1250c 7d6e00c 6f1250c c6054f0 85dd36a 43d87b3 85dd36a 5b88544 9271aef 7d6e00c 43d87b3 85dd36a 43d87b3 ee50e01 f2a79fa 7d6e00c f2a79fa |
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 |
import time
from http import HTTPStatus
from aws_lambda_powertools.utilities.typing import LambdaContext
from pydantic import ValidationError
from src import app_logger
from src.io.lambda_helpers import get_parsed_request_body, get_parsed_bbox_points, get_response
from src.prediction_api.predictors import samexporter_predict
def lambda_handler(event: dict, context: LambdaContext):
app_logger.info(f"start with aws_request_id:{context.aws_request_id}.")
start_time = time.time()
if "version" in event:
app_logger.info(f"event version: {event['version']}.")
try:
app_logger.info(f"try get_parsed_event...")
request_input = get_parsed_request_body(event)
app_logger.info(f"event parsed: ok")
body_request = get_parsed_bbox_points(request_input)
try:
app_logger.info(f"body_request => {type(body_request)}, {body_request}.")
body_response = samexporter_predict(body_request["bbox"], body_request["prompt"], body_request["zoom"])
app_logger.info(f"output body_response:{body_response}.")
response = get_response(HTTPStatus.OK.value, start_time, context.aws_request_id, body_response)
except Exception as ex2:
app_logger.error(f"exception2:{ex2}.")
response = get_response(HTTPStatus.BAD_REQUEST.value, start_time, context.aws_request_id, {})
except ValidationError as va1:
app_logger.error(f"ValidationError:{va1}.")
response = get_response(HTTPStatus.UNPROCESSABLE_ENTITY.value, start_time, context.aws_request_id, {})
except Exception as ex1:
app_logger.error(f"exception1:{ex1}.")
response = get_response(HTTPStatus.INTERNAL_SERVER_ERROR.value, start_time, context.aws_request_id, {})
app_logger.info(f"response_dumped:{response}...")
return response
|