Use wscat
to
connect to a WebSocket API and send messages to it
The wscat
utility is a convenient tool for testing a WebSocket API that you have created and
deployed in API Gateway. You can install and use wscat
as follows:
-
Download
wscat
from https://www.npmjs.com/package/wscat. -
Install
wscat
by running the following command:npm install -g wscat
-
To connect to your API, run the
wscat
command as shown in the following example. Note that this example assumes that theAuthorization
setting isNONE
.wscat -c wss://
aabbccddee
.execute-api.us-east-1
.amazonaws.com/test/You need to replace
with the actual API ID, which is displayed in the API Gateway console or returned by the AWS CLIaabbccddee
create-api
command.In addition, if your API is in a Region other than
us-east-1
, you need to substitute the correct Region. -
To test your API, enter a message such as the following while connected:
{"
{jsonpath-expression}
":"{route-key}
"}where
{jsonpath-expression}
is a JSONPath expression and{route-key}
is a route key for the API. For example:{"action":"action1"} {"message":"test response body"}
For more information about JSONPath, see JSONPath
or JSONPath for Java . -
To disconnect from your API, enter
ctrl-C
.