Skip to content

Subscription

Source: src/AWS/SNS/Subscription.ts

An Amazon SNS subscription that attaches an endpoint to a topic.

Subscription keeps the lifecycle of the subscription itself separate from the topic, which lets Lambda event sources and manually managed subscriptions share the same canonical resource model.

Lambda Subscription

const subscription = yield* Subscription("TopicSubscription", {
topicArn: topic.topicArn,
protocol: "lambda",
endpoint: fn.functionArn,
});

Fan Out a Topic to an SQS Queue

const topic = yield* SNS.Topic("Events");
const queue = yield* SQS.Queue("Notifications");
const subscription = yield* Subscription("QueueSubscription", {
topicArn: topic.topicArn,
protocol: "sqs",
endpoint: queue.queueArn,
returnSubscriptionArn: true,
});

Filtered Subscription

const subscription = yield* Subscription("OrderSubscription", {
topicArn: topic.topicArn,
protocol: "sqs",
endpoint: queue.queueArn,
attributes: {
FilterPolicy: JSON.stringify({ type: ["order"] }),
},
});