How do I use AWS SNS with EventBridge Schemas?
In this example, we will create an AWS SNS Topic and integrate it with AWS EventBridge Schemas. We will create an EventBridge Schema and a Discoverer, and then configure SNS to receive events based on this schema.
Key Points
- Create an SNS Topic to handle event notifications.
- Define an EventBridge Schema to structure the event data.
- Set up a Discoverer to automatically discover schemas from event sources.
- Integrate the SNS Topic with the EventBridge schema to receive events.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an SNS Topic
const snsTopic = new aws.sns.Topic("snsTopic");
// Create an EventBridge Schema
const eventSchema = new aws.schemas.Schema("eventSchema", {
content: JSON.stringify({
type: "object",
properties: {
id: { type: "string" },
detail: { type: "object" },
source: { type: "string" },
time: { type: "string" },
},
required: ["id", "detail", "source", "time"],
}),
registryName: "default",
type: "OpenApi3",
});
// Create a Discoverer for the schema
const discoverer = new aws.schemas.Discoverer("discoverer", {
sourceArn: snsTopic.arn,
});
// Create a Subscription to the SNS Topic
const snsSubscription = new aws.sns.TopicSubscription("snsSubscription", {
topic: snsTopic.arn,
protocol: "email",
endpoint: "example@example.com", // Replace with your email address
});
// Export the SNS Topic ARN and Event Schema ARN
export const snsTopicArn = snsTopic.arn;
export const eventSchemaArn = eventSchema.arn;
Summary
In this program, we created an SNS Topic and an EventBridge Schema. We then set up a Discoverer to automatically discover schemas from event sources and integrated the SNS Topic with the EventBridge schema to receive events. This setup enables SNS to handle notifications based on structured event data defined by the schema.
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.