1. Answers
  2. Building an AWS SNS Topic Subscription

How do I build an AWS SNS topic subscription?

To create an AWS SNS topic and a subscription using Pulumi, you will need to define both the SNS topic and the subscription in your Pulumi program. Below is a complete example in TypeScript.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an SNS Topic
const topic = new aws.sns.Topic("myTopic", {
    // Optional parameters can be added here
});

// Create an SNS Topic Subscription
const subscription = new aws.sns.TopicSubscription("mySubscription", {
    topic: topic.arn,
    protocol: "email",  // Protocol can be "email", "sms", "lambda", etc.
    endpoint: "example@example.com",  // Replace with your email address or other endpoint
    // Additional optional parameters can be added here
});

// Export the topic ARN and subscription ARN
export const topicArn = topic.arn;
export const subscriptionArn = subscription.arn;

In this program:

  1. We import the necessary Pulumi and AWS libraries.
  2. We create an SNS topic using the aws.sns.Topic resource.
  3. We create an SNS topic subscription using the aws.sns.TopicSubscription resource, specifying the topic ARN, protocol, and endpoint.
  4. Finally, we export the ARNs of both the topic and the subscription.

This example demonstrates how to set up an SNS topic and a subscription in AWS using Pulumi. You can modify the protocol and endpoint to match your specific use case.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up