You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+108Lines changed: 108 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ Event handler for Amazon API Gateway REST and HTTP APIs, Application Load Balanc
11
11
* Support for CORS, binary and Gzip compression, Decimals JSON encoding and bring your own JSON serializer
12
12
* Built-in integration with [Event Source Data Classes utilities](../../utilities/data_classes.md){target="_blank"} for self-documented event schema
13
13
* Works with micro function (one or a few routes) and monolithic functions (all routes)
14
+
* Native async handler support with `resolve_async()` for non-blocking I/O
14
15
* Support for Middleware
15
16
* Support for OpenAPI schema generation
16
17
* Support data validation for requests/responses
@@ -1464,6 +1465,99 @@ Use `dependency_overrides` to replace any dependency with a mock or stub during
1464
1465
???+ info "`append_context` vs `Depends()`"
1465
1466
`append_context` remains available for backward compatibility. `Depends()` is recommended for new code because it provides type safety, IDE autocomplete, composable dependency trees, and `dependency_overrides` for testing.
1466
1467
1468
+
### Async support
1469
+
1470
+
Use `resolve_async()` to natively support async route handlers with `async/await`. This enables non-blocking I/O operations like concurrent HTTP calls, database queries, and parallel processing within your Lambda function.
1471
+
1472
+
Both sync and async handlers can coexist in the same resolver. Async handlers are automatically detected and awaited.
|**AWS X-Ray with `asyncio.gather`**| X-Ray SDK does not propagate trace context across `asyncio.gather` tasks. Use individual `await` calls if you need per-call tracing. |
1559
+
|**Sync middlewares use thread pool**| Sync middlewares run in the default `ThreadPoolExecutor`. Avoid long blocking I/O inside sync middlewares when using `resolve_async()`. |
1560
+
1467
1561
### Considerations
1468
1562
1469
1563
This utility is optimized for fast startup, minimal feature set, and to quickly on-board customers familiar with frameworks like Flask — it's not meant to be a fully fledged framework.
@@ -1546,6 +1640,20 @@ Each endpoint will be it's own Lambda function that is configured as a [Lambda i
1546
1640
1547
1641
## Testing your code
1548
1642
1643
+
### Testing async handlers
1644
+
1645
+
You can test async handlers by calling `resolve_async()` with `asyncio.run()`.
0 commit comments