Realtime
Reference doc for the `sst.aws.Realtime` component.
The Realtime
component lets you publish and subscribe to messages in realtime.
It offers a topic-based messaging network using AWS IoT. Letting you publish and subscribe to messages using a WebSocket in the browser and your server.
Also, provides an SDK to authorize clients, grant permissions to subscribe, and publish to topics.
There is only 1 IoT endpoint per region per AWS account. Messages from all apps and stages are published to the same IoT endpoint. Make sure to prefix the topics by the app and stage name.
Create a realtime endpoint
Authorize the client
Publish and receive messages in your frontend
Subscribe messages in your backend
Publish message from your backend
Constructor
Parameters
-
name
string
-
args
RealtimeArgs
-
opts?
ComponentResourceOptions
RealtimeArgs
authorizer
Type Input
<
string
|
FunctionArgs
>
The Lambda function that’ll be used to authorize the client on connection.
transform?
Type Object
Transform how this subscription creates its underlying resources.
transform.authorizer?
Type AuthorizerArgs
|
(
args
:
AuthorizerArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the IoT authorizer resource.
Properties
authorizer
Type Output
<
string
>
The name of the IoT authorizer.
endpoint
Type Output
<
string
>
The IoT endpoint.
nodes
Type Object
The underlying resources this component creates.
nodes.authHandler
Type Output
<
Function
>
The IoT authorizer function resource.
nodes.authorizer
Type Authorizer
The IoT authorizer resource.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
authorizer
string
The name of the IoT authorizer.
-
endpoint
string
The IoT endpoint.
The realtime
client SDK is available through the following.
authorizer
Parameters
-
input
(token:
string
) =>Promise
<
AuthResult
>
Returns IoTCustomAuthorizerHandler
Creates an authorization handler for the Realtime
component. It validates
the token and grants permissions for the topics the client can subscribe and publish to.
AuthResult
Type Object
AuthResult.disconnectAfterInSeconds?
Type number
Default 86400
The maximum duration in seconds of the connection to IoT Core.
The minimum value is 300 seconds, and the maximum is 86400 seconds.
AuthResult.policyDocuments?
Type PolicyDocument
[]
Any additional IoT Core policy documents to attach to the client.
There’s a maximum of 10 policy documents. Where each document can contain a maximum of 2048 characters.
AuthResult.principalId?
Type string
The principal ID of the authorized client. This could be a user ID, username, or phone number.
The value must be an alphanumeric string with at least one, and no more than 128,
characters and match the regex pattern, ([a-zA-Z0-9]){1,128}
.
AuthResult.publish?
Type string
[]
The topics the client can publish to.
For example, this publishes to two specific topics.
And to publish to all topics under a given prefix.
AuthResult.refreshAfterInSeconds?
Type number
The duration in seconds between policy refreshes. After the given duration, IoT Core will invoke the authorization handler function.
The minimum value is 300 seconds, and the maximum value is 86400 seconds.
AuthResult.subscribe?
Type string
[]
The topics the client can subscribe to.
For example, this subscribes to two specific topics.
And to subscribe to all topics under a given prefix.
Methods
subscribe
Parameters
The function that’ll be notified.subscriber
Input
<
string
|
FunctionArgs
|
“arn:aws:lambda:${string}”
>
- Configure the subscription.
Returns Output
<
RealtimeLambdaSubscriber
>
Subscribe to this Realtime server.
Customize the subscriber function.
Or pass in the ARN of an existing Lambda function.
RealtimeSubscriberArgs
filter
Type Input
<
string
>
Filter the topics that’ll be processed by the subscriber.
Subscribe to a specific topic.
Subscribe to all topics under a prefix.
transform?
Type Object
Transform how this subscription creates its underlying resources.
transform.topicRule?
Type TopicRuleArgs
|
(
args
:
TopicRuleArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the IoT Topic rule resource.