SnsTopic
Reference doc for the `sst.aws.SnsTopic` component.
The SnsTopic
component lets you add an Amazon SNS Topic to your app.
Create a topic
Make it a FIFO topic
You can optionally make it a FIFO topic.
Add a subscriber
Link the topic to a resource
You can link the topic to other resources, like a function or your Next.js app.
Once linked, you can publish messages to the topic from your function code.
Constructor
Parameters
-
name
string
-
args?
SnsTopicArgs
-
opts?
ComponentResourceOptions
SnsTopicArgs
fifo?
Type Input
<
boolean
>
Default false
FIFO (First-In-First-Out) topics are designed to provide strict message ordering.
transform?
transform.topic?
Type TopicArgs
|
(
args
:
TopicArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the SNS Topic resource.
Properties
arn
Type Output
<
string
>
The ARN of the SNS Topic.
name
Type Output
<
string
>
The name of the SNS Topic.
nodes
nodes.topic
Type Topic
The Amazon SNS Topic.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
arn
string
The ARN of the SNS Topic.
Methods
subscribe
Parameters
The name of the subscriber.name
string
The function that’ll be notified.subscriber
Input
<
string
|
FunctionArgs
|
“arn:aws:lambda:${string}”
>
Configure the subscription.args?
SnsTopicSubscriberArgs
Returns Output
<
SnsTopicLambdaSubscriber
>
Subscribe to this SNS Topic.
Add a filter to the subscription.
Customize the subscriber function.
Or pass in the ARN of an existing Lambda function.
subscribeQueue
Parameters
The name of the subscriber.name
string
The ARN of the queue orqueue
Input
<
string
|
Queue
>
Queue
component that’ll be notified.
Configure the subscription.args?
SnsTopicSubscriberArgs
Returns Output
<
SnsTopicQueueSubscriber
>
Subscribe to this SNS Topic with an SQS Queue.
For example, let’s say you have a queue.
You can subscribe to this topic with it.
Add a filter to the subscription.
static subscribe
Parameters
The name of the subscriber.name
string
The ARN of the SNS Topic to subscribe to.topicArn
Input
<
string
>
The function that’ll be notified.subscriber
Input
<
string
|
FunctionArgs
|
“arn:aws:lambda:${string}”
>
Configure the subscription.args?
SnsTopicSubscriberArgs
Returns Output
<
SnsTopicLambdaSubscriber
>
Subscribe to an SNS Topic that was not created in your app.
For example, let’s say you have an existing SNS Topic with the following ARN.
You can subscribe to it by passing in the ARN.
Add a filter to the subscription.
Customize the subscriber function.
static subscribeQueue
Parameters
The name of the subscriber.name
string
The ARN of the SNS Topic to subscribe to.topicArn
Input
<
string
>
The ARN of the queue orqueue
Input
<
string
|
Queue
>
Queue
component that’ll be notified.
Configure the subscription.args?
SnsTopicSubscriberArgs
Returns Output
<
SnsTopicQueueSubscriber
>
Subscribe to an existing SNS Topic with a previously created SQS Queue.
For example, let’s say you have an existing SNS Topic and SQS Queue with the following ARNs.
You can subscribe to the topic with the queue.
Add a filter to the subscription.
SnsTopicSubscriberArgs
filter?
Type Input
<
Record
<
string
, any
>
>
Filter the messages that’ll be processed by the subscriber.
If any single property in the filter doesn’t match an attribute assigned to the message, then the policy rejects the message.
For example, if your SNS Topic message contains this in a JSON format.
Then this filter policy accepts the message.
transform?
Type Object
Transform how this subscription creates its underlying resources.
transform.subscription?
Type TopicSubscriptionArgs
|
(
args
:
TopicSubscriptionArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the SNS Topic Subscription resource.