How to pass parameter from main lambda handler to event handlerroute #1546
-
Assume a main lambda method, where we construct some variable: @logger.inject_lambda_context()
@event_source(data_class=LambdaFunctionUrlEvent)
def lambda_handler(event: LambdaFunctionUrlEvent, context: LambdaContext) -> dict:
# Parse & construct some parameters
parameters = dict(parse_qsl(event.decoded_body))
# Create a CallContext object
call_context = CallContext(db, parameters)
return app.resolve(event, context) What is a good way to pass this @app.post("/dial_call_status")
def dial_call_status():
# How to access call_context here? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey @MaartenUreel, we don't provide a dependency injection (DI) feature in Event Handler at the moment, so you'd have to handle @app.post("/dial_call_status")
def dial_call_status():
parameters = dict(parse_qsl(app.current_event.decoded_body))
# Create a CallContext object
call_context = CallContext(db, parameters) If your need is more advanced, we'd love to discuss how a DI would look like in a RFC format for Event Handler. As DI has some cognitive load, I'd be looking at (1) UX of providing/depending on X, (2) whether any Callable suffice, (3) whether we should call it only once if a dependency is used multiple times (e.g., cache=True), and (4) whether we want to limit the depth of a graph (e.g., sub-sub-sub-dependencies). Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
OK; I hadded it to |
Beta Was this translation helpful? Give feedback.
-
I opened up an RFC anyway because I find I have too much boilerplate code now in every request. |
Beta Was this translation helpful? Give feedback.
I opened up an RFC anyway because I find I have too much boilerplate code now in every request.
I hope I did it according to standards ;-)