Set up route responses for a WebSocket API in API Gateway
WebSocket routes can be configured for two-way or one-way communication. If a route has a route response, it is configured for two-way communication. Otherwise, it is configured for one-way communication. Route responses are used to enable two-way communication, in which your API can send a response back to the client in the context of the client's message.
You can configure route responses and response selection expressions by using the API Gateway console or the AWS CLI or an AWS SDK. For more information about route responses, see Invoking your backend integration: $default Route and custom routes.
For more information about route response selection expressions, see Route response selection expressions.
Topics
Set up a route response using the API Gateway console
To set up a route response for a WebSocket API using the API Gateway console:
-
Sign in to the API Gateway console, choose the API.
-
Under Routes, choose the route.
-
Choose Route Response in the route overview pane.
-
Under Response Modeling, in the Response Selection Expression box, enter the desired response selection expression and choose the checkmark icon.
-
Under Route Responses, under Response Key, choose Add Response.
Note Currently only
$default
is supported in route responses for WebSocket APIs. -
Enter the response key name and choose the checkmark icon.
Set up a route response using the AWS CLI
To set up a route response for a WebSocket API using the AWS CLI, call the create-route-response
command as shown in the following
example. You can identify the API ID and route ID by calling get-apis
and get-routes
.
aws apigatewayv2 create-route-response \ --api-id
aabbccddee
\ --route-id1122334
\ --route-response-key '$default'
Example output:
{ "RouteResponseId": "abcdef", "RouteResponseKey": "$default" }