Create a WebSocket API in API Gateway
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.
WebSocket APIs only support TLS 1.2. Earlier TLS versions are not supported.
Create a WebSocket API using AWS CLI commands
Creating a WebSocket API using the AWS 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.
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.
-
Under Settings, in the API name field, enter the name of your API, for example,
PetStore
. -
Enter a Route Selection Expression for your API, for example,
$request.body.action
.For more information about route selection expressions, see Route selection expressions.
-
If desired, enter a Description for your API.
-
Choose Create API.