From b8706665d21b0e533433308f6e2102b57845fafd Mon Sep 17 00:00:00 2001 From: Joel Balcaen Date: Fri, 19 Apr 2024 11:53:45 -0300 Subject: [PATCH] properly handle errors --- lambdas/step_function_invoker/src/index.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lambdas/step_function_invoker/src/index.py b/lambdas/step_function_invoker/src/index.py index fdc1aed..13c6087 100644 --- a/lambdas/step_function_invoker/src/index.py +++ b/lambdas/step_function_invoker/src/index.py @@ -2,6 +2,7 @@ import boto3 import os from aws_lambda_powertools import Logger, Metrics +from botocore.exceptions import ParamValidationError logger = Logger() metrics = Metrics() @@ -17,7 +18,7 @@ def lambda_handler(event, context): try: state_machine_execution_result = step_functions_client.start_execution( stateMachineArn=STATE_MACHINE_ARN, - input=json.dumps(event), + input=event, ) return { @@ -25,6 +26,12 @@ def lambda_handler(event, context): "body": json.dumps(state_machine_execution_result), } + except ParamValidationError as e: + return { + "statusCode": 400, + "body": json.dumps({"error": "Parameter validation error", "details": str(e)}), + } + except Exception as e: return { "statusCode": 400,