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:
- We import the necessary Pulumi and AWS libraries.
- We create an SNS topic using the
aws.sns.Topic
resource. - We create an SNS topic subscription using the
aws.sns.TopicSubscription
resource, specifying the topic ARN, protocol, and endpoint. - 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 upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.