Overview
TheSNSTopic construct creates an Amazon SNS topic for pub/sub messaging. Use it to fan out events to multiple subscribers (Lambda, SQS, HTTP endpoints) from a single publish call.
Import
Basic Usage
Using the Messaging Factory
The recommended way to add SNS to a Fjall application is through theMessagingFactory:
Properties
| Property | Type | Default | Description |
|---|---|---|---|
topicName | string | Auto-generated | Topic name |
displayName | string | None | Human-readable name for SMS subscriptions |
fifo | boolean | false | Create a FIFO topic (strict ordering) |
contentBasedDeduplication | boolean | true (FIFO) | Content-based deduplication. Defaults to true on FIFO topics, ignored on standard topics |
removalPolicy | "DESTROY" | "RETAIN" | "RETAIN" | What happens on stack deletion |
Methods
| Method | Returns | Description |
|---|---|---|
getTopicArn() | string | Topic ARN |
getTopicName() | string | Topic name |
getTopic() | ITopic | CDK Topic construct |
grantPublish(grantee) | Grant | Grant permission to publish messages |
grantSubscribe(grantee) | Grant | Grant permission to subscribe to the topic |
Examples
Standard Topic
FIFO Topic
FIFO topics deliver messages in order and support deduplication:Fan-Out to Multiple Queues
Combine SNS with SQS for fan-out patterns:CloudFormation Outputs
| Output | Description |
|---|---|
{id}TopicArn | Topic ARN |
{id}TopicName | Topic name |
Next Steps
Messaging Factory
Create messaging resources via the factory pattern
SQS Queue
Combine with SQS for fan-out patterns