Amazon API Gateway
Developer Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

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.

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:

  1. Sign in to the API Gateway console, choose the API.

  2. Under Routes, choose the route.

  3. Choose Route Response in the route overview pane.

  4. Under Response Modeling, in the Response Selection Expression box, enter the desired response selection expression and choose the checkmark icon.

  5. Under Route Responses, under Response Key, choose Add Response.

    Note

    Currently only $default is supported in route responses for WebSocket APIs.

  6. 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.

aws apigatewayv2 --region us-east-1 create-route-response --api-id aabbccddee --route-id 1122334 --route-response-key $default

Example output:

{ "RouteResponseId": "abcdef", "RouteResponseKey": "$default" }