You can create a WebSocket API in the API Gateway console, by using the AWS CLI
create-api command, or by using the CreateApi
command in an AWS SDK. The following procedures show how to
create a new WebSocket API.
Note
WebSocket APIs only support TLS 1.2 and TLS 1.3. Earlier TLS versions are not supported.
Create a WebSocket
API using AWS CLI commands
The following create-api command 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'
The output looks like the following:
{ "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
-
Sign in to the API Gateway console and choose Create API.
-
Under WebSocket API, choose Build. Only Regional endpoints are supported.
-
For API name, enter the name of your API.
-
For Route selection expression, enter a value. For example,
$request.body.action
.For more information about route selection expressions, see Route selection expressions.
-
Do one of the following:
-
Choose Create blank API to create an API with no routes.
-
Choose Next to attach routes to your API.
You can attach routes after you create your API.
-