MCPcopy Create free account
hub / github.com/aws-samples/personalization-apis / lambda_handler

Function lambda_handler

src/personalization_api_function/main.py:600–644  ·  view source on GitHub ↗

Main function entry point that delegates to request router

(event, context)

Source from the content-addressed store, hash-verified

598@tracer.capture_lambda_handler(capture_response=False)
599@metrics.log_metrics(capture_cold_start_metric=True)
600def lambda_handler(event, context):
601 """ Main function entry point that delegates to request router """
602 try:
603 return app.resolve(event, context)
604 except PersonalizationError as e:
605 logger.exception(e)
606 return {
607 'statusCode': e.status_code,
608 'headers': {
609 "Content-Type" : "application/json"
610 },
611 'body': json.dumps({
612 'type': e.type,
613 'code': e.error_code,
614 'message': e.error_message
615 })
616 }
617 except botocore.exceptions.ParamValidationError as e:
618 logger.exception(e)
619 return {
620 'statusCode': HTTPStatus.BAD_REQUEST,
621 'headers': {
622 "Content-Type" : "application/json"
623 },
624 'body': json.dumps({
625 'type': 'Validation',
626 'code': 'ValidationError',
627 'message': str(e)
628 })
629 }
630 except Exception as e:
631 logger.exception(e)
632 formatted_lines = traceback.format_exc().splitlines()
633 return {
634 'statusCode': HTTPStatus.INTERNAL_SERVER_ERROR,
635 'headers': {
636 "Content-Type" : "application/json"
637 },
638 'body': json.dumps({
639 'type': 'Unhandled',
640 'code': 'InternalError',
641 'message': str(e),
642 'details': formatted_lines
643 }, indent = 2)
644 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected