Replies: 1 comment 2 replies
-
Hi @natflow, thanks for the detailed feedback! The warning is mainly intended to signal that these handlers may see several breaking changes before settling on a stable design, though I think what currently exists mostly represents how these handlers will look going forward. I'll go ahead and state now that support for custom handlers will no longer be considered provisional in the next release. To address your feedback specifically:
It would seem the gist of my responses above is that I'm open to changes here to better accommodate the feature, but I need more clarity on how a custom handler might actually look and behave. |
Beta Was this translation helpful? Give feedback.
-
I thought I'd share some feedback on the custom event handler feature, especially given using it produces a warning about it being provisional and possibly eventually removed: I think they're great! I've written other event handlers by hand and done all the routing myself and it's a hassle and a lot of weird code.
My use-case was for a Lambda that is configured for Cognito trigger events in addition to API GW. I wrote a little class that did some checks (
event.get("triggerSource", "").startswith("PreSignUp_")
and translations (NOTIFY
HTTP method and/cognito/presignup_signup
path) and got the routing and dependency injection from FastAPI that I'd always wanted for these non-HTTP events.A few thoughts on improvements:
LambdaHandler.__init__
was actually used in the adapter'sinfer
or__call__
methods. If it's not being used anywhere else either I'd suggest removing it from the protocol to allow greater flexibility for the custom handlers.json.dumps
it forLambdaHandler.body
andjson.loads
it again in__call__
. Or maybe there's some ASGI extension or workaround? I haven't dug into it but I'm afraid any solution would be a combination of ASGI middleware, FastAPI middleware, and custom FastAPI Request/Response classes.HTTPScope
and many of them are typed as literals.LambdaHandler.scope
could be a lot simpler if there was some concept of default values -- either allowing for a partial object return (and Mangum would fill in the rest) or constructing a full object using some default object exported from Mangum (egreturn { **mangum.http_scope_defaults, **my_overrides }
).Beta Was this translation helpful? Give feedback.
All reactions