Use case
With the full async pipeline built internally (PRs 1-4), this final PR exposes resolve_async() to customers, enabling native async handler support in all Event Handler resolvers.
Solution/User Experience
app = APIGatewayHttpResolver()
# Sync - works exactly as before
@app.get("/health")
def health():
return {"status": "ok"}
# Async - native support
@app.get("/dashboard/<user_id>")
async def get_dashboard(user_id: str):
orders, profile = await asyncio.gather(
get_orders(user_id),
get_profile(user_id),
)
return {"orders": orders, "profile": profile}
def lambda_handler(event, context):
return asyncio.run(app.resolve_async(event, context))
What changes:
- Add public
resolve_async(event, context) method on ApiGatewayResolver
- Mirrors
resolve() setup (proxy event construction, context population, CORS, etc.)
- Delegates to
_resolve_async() from PR 4
- Add
resolve_async() to all resolver subclasses: APIGatewayRestResolver, APIGatewayHttpResolver, ALBResolver
- Documentation and examples
- E2E tests
What stays the same:
resolve() is untouched - fully backward compatible
- Sync and async handlers work in the same app
- All existing middlewares (sync) work without changes
- OpenAPI validation works with async handlers
- Route matching, serialization, compression - all CPU-bound, stay sync
Key design decisions:
resolve_async() is a new method, not a flag - explicit is better than implicit
- Sync middlewares work in async chain - threading bridge handles this transparently
- Auto-detection of async handlers -
inspect.iscoroutinefunction() at the adapter level, no decorator needed
- Same middleware chain order - Request Validation → Router Middlewares → Route Middlewares → Response Validation → API Adapter
Out of scope:
- Tracer / X-Ray with
asyncio.gather - known X-Ray SDK issue, tracked separately
- Async
resolve() replacing sync resolve() - breaking change, resolve_async() is additive
- Async-only validation/serialization - CPU-bound operations, no benefit from async
Alternative solutions
Acknowledgment
Use case
With the full async pipeline built internally (PRs 1-4), this final PR exposes
resolve_async()to customers, enabling native async handler support in all Event Handler resolvers.Solution/User Experience
What changes:
resolve_async(event, context)method onApiGatewayResolverresolve()setup (proxy event construction, context population, CORS, etc.)_resolve_async()from PR 4resolve_async()to all resolver subclasses:APIGatewayRestResolver,APIGatewayHttpResolver,ALBResolverWhat stays the same:
resolve()is untouched - fully backward compatibleKey design decisions:
resolve_async()is a new method, not a flag - explicit is better than implicitinspect.iscoroutinefunction()at the adapter level, no decorator neededOut of scope:
asyncio.gather- known X-Ray SDK issue, tracked separatelyresolve()replacing syncresolve()- breaking change,resolve_async()is additiveAlternative solutions
Acknowledgment