Documentation Index
Fetch the complete documentation index at: https://mintlify.com/anomalyco/sst/llms.txt
Use this file to discover all available pages before exploring further.
The Realtime component lets you add pub/sub messaging to your app using WebSockets. It uses Amazon API Gateway WebSocket API.
Constructor
const realtime = new sst.aws.Realtime("MyRealtime", {
authorizer: "src/authorizer.handler"
});
Parameters
authorizer
The Lambda function to authorize connections.{
authorizer: "src/authorizer.handler"
}
Properties
url
nodes
SDK
Publish messages to connected clients:
import { Resource } from "sst";
import { ApiGatewayManagementApiClient, PostToConnectionCommand } from "@aws-sdk/client-apigatewaymanagementapi";
const client = new ApiGatewayManagementApiClient({
endpoint: Resource.MyRealtime.url
});
await client.send(new PostToConnectionCommand({
ConnectionId: connectionId,
Data: JSON.stringify({ message: "Hello" })
}));
Examples
Create a realtime component
const realtime = new sst.aws.Realtime("MyRealtime", {
authorizer: "src/authorizer.handler"
});
realtime.subscribe("$default", "src/default.handler");
realtime.subscribe("sendMessage", "src/sendMessage.handler");