An Amazon SNS topic is a logical access point that acts as a communication channel. A topic lets you group multiple endpoints (such as AWS Lambda, Amazon SQS, HTTP/S, or an email address).
To broadcast the messages of a message-producer system (for example, an e-commerce website) working with multiple other services that require its messages (for example, checkout and fulfillment systems), you can create a topic for your producer system.
The first and most common Amazon SNS task is creating a topic. This page shows how you can use the AWS Management Console, the AWS SDK for Java, and the AWS SDK for .NET to create a topic.
During creation, you choose a topic type (standard or FIFO) and name the topic. After creating a topic, you can't change the topic type or name. All other configuration choices are optional during topic creation, and you can edit them later.
Important
Do not add personally identifiable information (PII) or other confidential or sensitive information in topic names. Topic names are accessible to other Amazon Web Services, including CloudWatch Logs. Topic names are not intended to be used for private or sensitive data.
To create a topic using the AWS Management Console
Creating a topic in Amazon SNS establishes the foundation for message distribution, enabling you to publish messages that can be fanned out to multiple subscribers. This step is essential to configure the topic's type, encryption settings, and access policies, ensuring the topic meets the organization’s security, compliance, and operational requirements.
Sign in to the Amazon SNS console
. -
Do one of the following:
-
If no topics have ever been created under your AWS account before, read the description of Amazon SNS on the home page.
-
If topics have been created under your AWS account before, on the navigation panel, choose Topics.
-
-
On the Topics page, choose Create topic.
-
On the Create topic page, in the Details section, do the following:
-
For Type, choose a topic type (Standard or FIFO).
-
Enter a Name for the topic. For a FIFO topic, add .fifo to the end of the name.
-
(Optional) Enter a Display name for the topic.
Important
When subscribing to an email endpoint, the combined character count for the Amazon SNS topic display name and the sending email address (for example, no-reply@sns.amazonaws.com) must not exceed 320 UTF-8 characters. You can use a third party encoding tool to verify the length of the sending address before configuring a display name for your Amazon SNS topic.
-
(Optional) For a FIFO topic, you can choose content-based message deduplication to enable default message deduplication. For more information, see Amazon SNS message deduplication for FIFO topics.
-
-
(Optional) Expand the Encryption section and do the following. For more information, see Securing Amazon SNS data with server-side encryption.
-
Choose Enable encryption.
-
Specify the AWS KMS key. For more information, see Key terms.
For each KMS type, the Description, Account, and KMS ARN are displayed.
Important
If you aren't the owner of the KMS, or if you log in with an account that doesn't have the
kms:ListAliases
andkms:DescribeKey
permissions, you won't be able to view information about the KMS on the Amazon SNS console.Ask the owner of the KMS to grant you these permissions. For more information, see the AWS KMS API Permissions: Actions and Resources Reference in the AWS Key Management Service Developer Guide.
-
The AWS managed KMS for Amazon SNS (Default) alias/aws/sns is selected by default.
Note
Keep the following in mind:
-
The first time you use the AWS Management Console to specify the AWS managed KMS for Amazon SNS for a topic, AWS KMS creates the AWS managed KMS for Amazon SNS.
-
Alternatively, the first time you use the
Publish
action on a topic with SSE enabled, AWS KMS creates the AWS managed KMS for Amazon SNS.
-
-
To use a custom KMS from your AWS account, choose the KMS key field and then choose the custom KMS from the list.
Note
For instructions on creating custom KMSs, see Creating Keys in the AWS Key Management Service Developer Guide
-
To use a custom KMS ARN from your AWS account or from another AWS account, enter it into the KMS key field.
-
-
-
(Optional) By default, only the topic owner can publish or subscribe to the topic. To configure additional access permissions, expand the Access policy section. For more information, see Identity and access management in Amazon SNS and Example cases for Amazon SNS access control.
Note
When you create a topic using the console, the default policy uses the
aws:SourceOwner
condition key. This key is similar toaws:SourceAccount
. -
(Optional) To configure how Amazon SNS retries failed message delivery attempts, expand the Delivery retry policy (HTTP/S) section. For more information, see Amazon SNS message delivery retries.
-
(Optional) To configure how Amazon SNS logs the delivery of messages to CloudWatch, expand the Delivery status logging section. For more information, see Amazon SNS message delivery status.
-
(Optional) To add metadata tags to the topic, expand the Tags section, enter a Key and a Value (optional) and choose Add tag. For more information, see Amazon SNS topic tagging.
-
Choose Create topic.
The topic is created and the
MyTopic
page is displayed.The topic's Name, ARN, (optional) Display name, and Topic owner's AWS account ID are displayed in the Details section.
-
Copy the topic ARN to the clipboard, for example:
arn:aws:sns:us-east-2:123456789012:MyTopic
To create a topic using an AWS SDK
To use an AWS SDK, you must configure it with your credentials. For more information, see The shared config and credentials files in the AWS SDKs and Tools Reference Guide.
The following code examples show how to use CreateTopic
.
- AWS SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Create a topic with a specific name.
using System; using System.Threading.Tasks; using Amazon.SimpleNotificationService; using Amazon.SimpleNotificationService.Model; /// <summary> /// This example shows how to use Amazon Simple Notification Service /// (Amazon SNS) to add a new Amazon SNS topic. /// </summary> public class CreateSNSTopic { public static async Task Main() { string topicName = "ExampleSNSTopic"; IAmazonSimpleNotificationService client = new AmazonSimpleNotificationServiceClient(); var topicArn = await CreateSNSTopicAsync(client, topicName); Console.WriteLine($"New topic ARN: {topicArn}"); } /// <summary> /// Creates a new SNS topic using the supplied topic name. /// </summary> /// <param name="client">The initialized SNS client object used to /// create the new topic.</param> /// <param name="topicName">A string representing the topic name.</param> /// <returns>The Amazon Resource Name (ARN) of the created topic.</returns> public static async Task<string> CreateSNSTopicAsync(IAmazonSimpleNotificationService client, string topicName) { var request = new CreateTopicRequest { Name = topicName, }; var response = await client.CreateTopicAsync(request); return response.TopicArn; } }
Create a new topic with a name and specific FIFO and de-duplication attributes.
/// <summary> /// Create a new topic with a name and specific FIFO and de-duplication attributes. /// </summary> /// <param name="topicName">The name for the topic.</param> /// <param name="useFifoTopic">True to use a FIFO topic.</param> /// <param name="useContentBasedDeduplication">True to use content-based de-duplication.</param> /// <returns>The ARN of the new topic.</returns> public async Task<string> CreateTopicWithName(string topicName, bool useFifoTopic, bool useContentBasedDeduplication) { var createTopicRequest = new CreateTopicRequest() { Name = topicName, }; if (useFifoTopic) { // Update the name if it is not correct for a FIFO topic. if (!topicName.EndsWith(".fifo")) { createTopicRequest.Name = topicName + ".fifo"; } // Add the attributes from the method parameters. createTopicRequest.Attributes = new Dictionary<string, string> { { "FifoTopic", "true" } }; if (useContentBasedDeduplication) { createTopicRequest.Attributes.Add("ContentBasedDeduplication", "true"); } } var createResponse = await _amazonSNSClient.CreateTopicAsync(createTopicRequest); return createResponse.TopicArn; }
-
For API details, see CreateTopic in AWS SDK for .NET API Reference.
-