A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Amazon Simple Notification Service (SNS) is a fully managed pub/sub messaging service for application-to-application (A2A) and application-to-person (A2P) communication.
import * as aws from "@pulumi/aws";
import * as sns from "@pulumi/aws/sns";SNS topic for pub/sub messaging.
const topic = new aws.sns.Topic("notifications", {
name: "app-notifications",
displayName: "Application Notifications",
tags: {
Environment: "production",
},
});Subscribe to an SNS topic.
const subscription = new aws.sns.TopicSubscription("email-sub", {
topic: topic.arn,
protocol: "email",
endpoint: "admin@example.com",
});const subscription = new aws.sns.TopicSubscription("lambda-sub", {
topic: topic.arn,
protocol: "lambda",
endpoint: lambdaFunction.arn,
});
new aws.lambda.Permission("sns-invoke", {
action: "lambda:InvokeFunction",
function: lambdaFunction.arn,
principal: "sns.amazonaws.com",
sourceArn: topic.arn,
});const queue = new aws.sqs.Queue("notifications-queue");
const subscription = new aws.sns.TopicSubscription("sqs-sub", {
topic: topic.arn,
protocol: "sqs",
endpoint: queue.arn,
});
new aws.sqs.QueuePolicy("queue-policy", {
queueUrl: queue.url,
policy: pulumi.all([topic.arn, queue.arn]).apply(([topicArn, queueArn]) =>
JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Principal: "*",
Action: "sqs:SendMessage",
Resource: queueArn,
Condition: {
ArnEquals: {
"aws:SourceArn": topicArn,
},
},
}],
})
),
});const kmsKey = new aws.kms.Key("sns-key", {
description: "SNS topic encryption key",
});
const topic = new aws.sns.Topic("encrypted-topic", {
name: "encrypted-notifications",
kmsMasterKeyId: kmsKey.id,
});const subscription = new aws.sns.TopicSubscription("filtered-sub", {
topic: topic.arn,
protocol: "sqs",
endpoint: queue.arn,
filterPolicy: JSON.stringify({
eventType: ["order_placed", "order_shipped"],
price: [{ numeric: [">=", 100] }],
}),
});name - Topic namedisplayName - Display name for SMS subscriptionsdeliveryPolicy - Message delivery retry policykmsMasterKeyId - KMS key for encryptionfifoTopic - Enable FIFO topiccontentBasedDeduplication - Enable content-based deduplication (FIFO only)topic - Topic ARNprotocol - Protocol (email, sms, sqs, lambda, http, https)endpoint - Endpoint to receive messagesfilterPolicy - Message filtering policyrawMessageDelivery - Enable raw message deliveryid - Resource identifierarn - Resource ARNname - Topic nameInstall with Tessl CLI
npx tessl i tessl/npm-pulumi--aws