Create a WebSocket API in API Gateway - Amazon API Gateway
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Create a WebSocket API in API Gateway

You can create a WebSocket API in the API Gateway console, by using the Amazon CLI create-api command, or by using the CreateApi command in an Amazon SDK. The following procedures show how to create a new WebSocket API.

Note

WebSocket APIs only support TLS 1.2. Earlier TLS versions are not supported.

Create a WebSocket API using Amazon CLI commands

Creating a WebSocket API using the Amazon CLI requires calling the create-api command as shown in the following example, which creates an API with the $request.body.action route selection expression:

aws apigatewayv2 --region us-east-1 create-api --name "myWebSocketApi3" --protocol-type WEBSOCKET --route-selection-expression '$request.body.action'

Example output:

{ "ApiKeySelectionExpression": "$request.header.x-api-key", "Name": "myWebSocketApi3", "CreatedDate": "2018-11-15T06:23:51Z", "ProtocolType": "WEBSOCKET", "RouteSelectionExpression": "'$request.body.action'", "ApiId": "aabbccddee" }

Create a WebSocket API using the API Gateway console

You can create a WebSocket API in the console by choosing the WebSocket protocol and giving the API a name.

Important

Once you have created the API, you cannot change the protocol you have chosen for it. There is no way to convert a WebSocket API into a REST API or vice versa.

To create a WebSocket API using the API Gateway console

  1. Sign in to the API Gateway console and choose Create API.

  2. Under WebSocket API, choose Build.

  3. Under Settings, in the API name field, enter the name of your API, for example, PetStore.

  4. Enter a Route Selection Expression for your API, for example, $request.body.action.

    For more information about route selection expressions, see Route selection expressions.

  5. If desired, enter a Description for your API.

  6. Choose Create API.