Use case
The current MiddlewareFrame is synchronous - it builds a recursive call chain where each middleware calls the next synchronously. To support async handlers, we need an async counterpart that can await async middlewares while still supporting existing sync middlewares transparently.
Solution/User Experience
- Add
AsyncMiddlewareFrame class in aws_lambda_powertools/event_handler/api_gateway.py (next to MiddlewareFrame)
- Auto-detects sync vs async middleware using
inspect.iscoroutinefunction()
- For async middleware:
awaits it directly
- For sync middleware: uses the threading utilities extracted in PR 1
- Unit tests for the new class
- Nothing calls it yet in production code - internal building block only
Alternative solutions
Acknowledgment
Use case
The current
MiddlewareFrameis synchronous - it builds a recursive call chain where each middleware calls the next synchronously. To support async handlers, we need an async counterpart that canawaitasync middlewares while still supporting existing sync middlewares transparently.Solution/User Experience
AsyncMiddlewareFrameclass inaws_lambda_powertools/event_handler/api_gateway.py(next toMiddlewareFrame)inspect.iscoroutinefunction()awaits it directlyAlternative solutions
Acknowledgment