Amazon API Gateway · AsyncAPI Specification
Amazon API Gateway WebSocket API Protocol
Version 1.0.0
AsyncAPI description of the *platform protocol* exposed by Amazon API Gateway WebSocket APIs. Customer-deployed WebSocket APIs are message-routed based on a route selection expression evaluated against each incoming JSON message; this document specifies only the platform-defined surface (the WebSocket connection lifecycle and the route extraction model) plus the IAM-signed back-channel used by backend services to push messages to connected clients. Customer-specific application routes (the values matched by `routeSelectionExpression`) are intentionally NOT enumerated here, because they are defined per deployed API by the customer. Only the platform-reserved routes `$connect`, `$disconnect`, and `$default` are first-class.
View Spec
View on GitHub
API GatewayCloudRESTHTTPWebSocketServerlessMCPAgentCoreDeveloper PortalAsyncAPIWebhooksEvents
Channels
connection
Client sends a message frame to the WebSocket API.
The WebSocket connection itself. A client opens a single bidirectional WebSocket against this path; API Gateway then routes the lifecycle and each inbound JSON message through the routing model described below. Route selection is configured at the API level by `routeSelectionExpression` (e.g. `${request.body.action}`). API Gateway evaluates the expression against each inbound message and dispatches to the matching route key. Three route keys are reserved by the platform: - `$connect` - invoked once when the WebSocket connection is established. - `$disconnect` - invoked once when either side closes the connection. - `$default` - invoked for non-JSON messages or when no custom route key matches. Customer-defined route keys (matched against the value extracted by `routeSelectionExpression`) sit alongside these three platform routes and are not enumerated here.
lifecycle-connect
API Gateway delivers a `$connect` lifecycle event to the integration.
Platform-reserved route invoked exactly once when API Gateway accepts a new WebSocket connection. The integration receives no message body; instead it receives the connection's `requestContext`, query string, headers, and any identity claims. A non-2xx response from this route's integration causes API Gateway to reject the connection (used for AuthN/Z gating).
lifecycle-disconnect
API Gateway delivers a `$disconnect` lifecycle event to the integration.
Platform-reserved route invoked on connection teardown (client close, server-side `DELETE @connections/{id}`, idle timeout at 10 minutes, or the 2-hour max connection lifetime). Best-effort delivery - integrations MUST treat it as an at-most-once notification.
lifecycle-default
API Gateway delivers an unrouted inbound message to the `$default` integration.
Platform-reserved fallback route. Invoked when the inbound payload is not valid JSON, when `routeSelectionExpression` cannot be evaluated against the payload, or when no customer-defined route key matches the extracted value.
Messages
RouteSelectedMessage
Client message matching a customer-defined route key
Inbound JSON message where the value extracted by `routeSelectionExpression` matches a customer-configured route key.
DefaultMessage
Client message routed to $default
Inbound message that did not match any custom route key, or that could not be parsed as JSON for route selection.
ServerMessage
Server-originated frame pushed to client
Outbound frame produced either by an integration response on the matched route or by a backend `PostToConnection` call against the ApiGatewayManagementApi.
ConnectEvent
$connect lifecycle event
DisconnectEvent
$disconnect lifecycle event
Servers
wss
production
{api-id}.execute-api.{region}.amazonaws.com
Default WebSocket connection endpoint for a deployed API Gateway WebSocket API. Clients connect to `wss://{api-id}.execute-api.{region}.amazonaws.com/{stage}`. The `stage` segment is included in the connection path (see channel address).
wss
custom-domain
{domain-name}
Optional custom domain name mapped to a WebSocket API stage via API Gateway custom domain names + ACM certificates. When a custom domain is in use the `stage` path segment is omitted from the connection URL.