Skip to content

Commit

Permalink
return saved attachments as lambda response
Browse files Browse the repository at this point in the history
  • Loading branch information
joelbalcaen committed Apr 19, 2024
1 parent 950bacf commit 3df5bd4
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions lambdas/step_function_invoker/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

step_functions_client = boto3.client("stepfunctions")
STATE_MACHINE_ARN = os.environ.get("STATE_MACHINE_ARN")
DISABLE_EVENT_PASS_THROUGH = os.environ.get("DISABLE_EVENT_PASS_THROUGH", False)

def json_serializer(obj):
"""JSON serializer for objects not serializable by default json code"""

if isinstance(obj, (datetime, date)):
return obj.isoformat()

raise TypeError ("Type %s not serializable" % type(obj))


Expand All @@ -25,15 +25,14 @@ def lambda_handler(event, context):
"""
This function is responsible for invoking the state machine with the given event.
The state machine arn is defined in the environment variable STATE_MACHINE_ARN.
The state machine can be invoked without passing the event to the state machine by setting the environment variable DISABLE_EVENT_PASS_THROUGH to True.
"""
logger.info(event)

try:
state_machine_execution_result = step_functions_client.start_execution(
stateMachineArn=STATE_MACHINE_ARN,
# default to str to get around the datetime serialization issue
input = json.dumps(event, default=json_serializer) if not DISABLE_EVENT_PASS_THROUGH else {},
input = json.dumps(event, default=json_serializer)
)

logger.info(state_machine_execution_result)
Expand All @@ -42,26 +41,11 @@ def lambda_handler(event, context):
"body": json.dumps(state_machine_execution_result),
}

except ParamValidationError as e:
logger.error(e)
return {
"statusCode": 400,
"body": json.dumps({"error": "Parameter validation error", "details": str(e)}),
}

except TypeError as e:
except (ParamValidationError, TypeError, Exception) as e:
logger.error(e)
return {
"statusCode": 400,
"body": json.dumps({"error": "Type error", "details": str(e)}),
"body": str(e)
}

except Exception as e:
logger.error(e)
return {
"statusCode": 400,
"body": json.dumps(e),
}



0 comments on commit 3df5bd4

Please sign in to comment.