Skip to content

Commit 073e08e

Browse files
committed
docs(event_handler): polish WebSocket resolver docs from final review
1 parent 8319886 commit 073e08e

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Core utilities such as Tracing, Logging, Metrics, and Event Handler are availabl
2424
* **[Event handler: AppSync](https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/appsync/)** - AppSync event handler for Lambda Direct Resolver and Amplify GraphQL Transformer function
2525
* **[Event handler: AppSync Events](https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/appsync_events/)** - AppSync Events handler for real-time WebSocket APIs with pub/sub pattern
2626
* **[Event handler: API Gateway, ALB, Lambda Function URL, VPC Lattice](https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/)** - REST/HTTP API event handler for Lambda functions invoked via Amazon API Gateway, ALB, Lambda Function URL, and VPC Lattice
27+
* **[Event handler: API Gateway WebSocket](https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway_websocket/)** - WebSocket API event handler for Lambda functions invoked via Amazon API Gateway WebSocket APIs
2728
* **[Event handler: Agents for Amazon Bedrock](https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/bedrock_agents/)** - Create Agents for Amazon Bedrock, automatically generating OpenAPI schemas
2829
* **[Middleware factory](https://docs.powertools.aws.dev/lambda/python/latest/utilities/middleware_factory/)** - Decorator factory to create your own middleware to run logic before, and after each Lambda invocation
2930
* **[Parameters](https://docs.powertools.aws.dev/lambda/python/latest/utilities/parameters/)** - Retrieve and cache parameter values from Parameter Store, Secrets Manager, AppConfig, or DynamoDB

aws_lambda_powertools/event_handler/api_gateway_websocket/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Router(BaseRouter):
2424
Registers route handlers for WebSocket route keys so they can be split across
2525
files and later included in an `APIGatewayWebSocketResolver` via `include_router`.
2626
27-
Parameters
27+
Attributes
2828
----------
2929
context : dict
3030
Dictionary to store context information accessible across route handlers

docs/core/event_handler/api_gateway_websocket.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ A returned dict is always body content — it is never inspected for a `statusCo
121121
The status code has different effects depending on the route:
122122

123123
* **`$connect`**: the status code decides the connection — 2xx accepts the WebSocket upgrade, anything else rejects it.
124-
* **All other routes**: the body is delivered back to the client only when the route has a route response configured, and a non-2xx status code does **not** drop the connection.
124+
* **All other routes**: the body is delivered back to the client only on routes with a [route response](#terminology), and a non-2xx status code does **not** drop the connection.
125+
126+
An event whose route key has no registered handler emits a `PowertoolsUserWarning` and returns `{"statusCode": 400}` — on `$connect`, that rejects the connection.
125127

126128
## Advanced
127129

@@ -145,7 +147,7 @@ Execution order is: global middlewares (`app.use`), then route-level `middleware
145147

146148
### Authentication patterns
147149

148-
`$connect` is the only route where credentials exist: headers and cookies are present on the WebSocket handshake only, and later messages carry nothing but the connection ID. There are two ways to bridge that gap.
150+
`$connect` is the only route where credentials exist: headers and cookies are present on the WebSocket handshake only, and later messages carry nothing from the client but the connection ID. There are two ways to bridge that gap.
149151

150152
#### Lambda authorizer
151153

@@ -229,7 +231,7 @@ Use `app.append_context` / `app.context` to share data between middlewares and h
229231

230232
### Sending messages to connected clients
231233

232-
Returned bodies only reply to the **calling** client, on routes with a route response. To push a message to a client at any time — including after the invocation that received the request has long finished — call the API Gateway Management API's `PostToConnection` with the connection ID, against the endpoint the `callback_url` property gives you.
234+
Returned bodies only reply to the **calling** client. To push a message to a client at any time — including after the invocation that received the request has long finished — call the API Gateway Management API's `PostToConnection` with the connection ID, against the endpoint the `callback_url` property gives you.
233235

234236
Capture `connection_id` and `callback_url` together at `$connect` and persist them: that record is everything **any** process needs to push to that client later.
235237

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverles
5252
| [Tracer](./core/tracer.md) | Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions |
5353
| [Logger](./core/logger.md) | Structured logging made easier, and target to enrich structured logging with key Lambda context details |
5454
| [Metrics](./core/metrics.md) | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) |
55-
| [Event Handler](./core/event_handler/api_gateway.md) | Event handler for API Gateway, ALB, Lambda Function URL, VPC Lattice, AppSync, and Bedrock Agents |
55+
| [Event Handler](./core/event_handler/api_gateway.md) | Event handler for API Gateway, ALB, Lambda Function URL, VPC Lattice, API Gateway WebSocket, AppSync, and Bedrock Agents |
5656
| [Parameters](./utilities/parameters.md) | Retrieve and cache parameter values from Parameter Store, Secrets Manager, AppConfig, or DynamoDB |
5757
| [Parser](./utilities/parser.md) | Data parsing and deep validation using Pydantic |
5858
| [Batch Processing](./utilities/batch.md) | Handle partial failures for SQS, Kinesis Data Streams, and DynamoDB Streams |

examples/event_handler_api_gateway_websocket/src/my_connection_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Illustrative connection store. In production, back these functions with a durable store
22
# such as a DynamoDB table: the WebSocket resolver and the functions that push results run
3-
# in different Lambda execution environments and cannot share process memory.
3+
# in different Lambda execution environments and cannot share process memory. Use a TTL —
4+
# $disconnect delivery is best-effort, so missed disconnects would leak entries forever.
45

56
_connections: dict[str, str] = {}
67

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ nav:
2222
- Event Handler:
2323
- core/event_handler/api_gateway.md
2424
- core/event_handler/openapi.md
25+
- core/event_handler/api_gateway_websocket.md
2526
- core/event_handler/appsync.md
2627
- core/event_handler/appsync_events.md
27-
- core/event_handler/api_gateway_websocket.md
2828
- core/event_handler/bedrock_agents.md
2929
- utilities/parameters.md
3030
- utilities/batch.md
@@ -244,9 +244,9 @@ plugins:
244244
- core/metrics.md
245245
- core/metrics/datadog.md
246246
- core/event_handler/api_gateway.md
247+
- core/event_handler/api_gateway_websocket.md
247248
- core/event_handler/appsync.md
248249
- core/event_handler/appsync_events.md
249-
- core/event_handler/api_gateway_websocket.md
250250
- core/event_handler/bedrock_agents.md
251251
Utilities:
252252
- utilities/parameters.md

0 commit comments

Comments
 (0)