Creating an Amazon SNS topic - Amazon Simple Notification Service
AWS services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with AWS services in China.

Creating an Amazon SNS topic

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.

To create a topic using the AWS Management Console

  1. Sign in to the Amazon SNS console.

  2. 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.

  3. On the Topics page, choose Create topic.

  4. On the Create topic page, in the Details section, do the following:

    1. For Type, choose a topic type (Standard or FIFO).

    2. Enter a Name for the topic. For a FIFO topic, add .fifo to the end of the name.

    3. (Optional) Enter a Display name for the topic.

    4. (Optional) For a FIFO topic, you can choose content-based message deduplication to enable default message deduplication. For more information, see Message deduplication for FIFO topics.

  5. (Optional) Expand the Encryption section and do the following. For more information, see Encryption at rest.

    1. Choose Enable encryption.

    2. Specify the customer master key (CMK). For more information, see Key terms.

      For each CMK type, the Description, Account, and CMK ARN are displayed.

      Important

      If you aren't the owner of the CMK, or if you log in with an account that doesn't have the kms:ListAliases and kms:DescribeKey permissions, you won't be able to view information about the CMK on the Amazon SNS console.

      Ask the owner of the CMK 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 CMK 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 CMK for Amazon SNS for a topic, AWS KMS creates the AWS managed CMK for Amazon SNS.

        • Alternatively, the first time you use the Publish action on a topic with SSE enabled, AWS KMS creates the AWS managed CMK for Amazon SNS.

      • To use a custom CMK from your AWS account, choose the Customer master key (CMK) field and then choose the custom CMK from the list.

        Note

        For instructions on creating custom CMKs, see Creating Keys in the AWS Key Management Service Developer Guide

      • To use a custom CMK ARN from your AWS account or from another AWS account, enter it into the Customer master key (CMK) field.

  6. (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 to aws:SourceAccount. For information about the differences between aws:SourceOwner and aws:SourceAccount, see aws:SourceAccount versus aws:SourceOwner.

  7. (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.

  8. (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.

  9. (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 Configuring tags for an Amazon SNS topic.

  10. 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.

  11. Copy the topic ARN to the clipboard, for example:

    arn:aws:sns:us-west-2:123456789012:MyTopic

To create a topic using the AWS SDK for Java

  1. Specify your AWS credentials. For more information, see Set up AWS Credentials and Region for Development in the AWS SDK for Java 2.x Developer Guide.

  2. Write your code. For more information, see Using the SDK for Java 2.x.

    The following code excerpt creates the topic MyTopic and then prints the topic ARN and the CreateTopicRequest request ID for a previously executed successful request.

    // Create an Amazon SNS topic. final CreateTopicRequest createTopicRequest = new CreateTopicRequest("MyTopic"); final CreateTopicResponse createTopicResponse = snsClient.createTopic(createTopicRequest); // Print the topic ARN. System.out.println("TopicArn:" + createTopicResponse.getTopicArn()); // Print the request ID for the CreateTopicRequest action. System.out.println("CreateTopicRequest: " + snsClient.getCachedResponseMetadata(createTopicRequest));
  3. Compile and run your code.

    The topic is created and the topic ARN and CreateTopicRequest request ID are printed, for example:

    TopicArn: arn:aws:sns:us-east-2:123456789012:MyTopic CreateTopicRequest: {AWS_REQUEST_ID=1234a567-bc89-012d-3e45-6fg7h890123i}
  4. You can assign the topic ARN to a String variable to use in additional operations, for example:

    final String topicArn = "arn:aws:sns:us-east-2:123456789012:MyTopic";

For a detailed example of how to create and publish a FIFO topic using the AWS SDK for Java, see Using the AWS SDK for Java 2.x.

To create a topic using the AWS SDK for .NET

  1. Specify your AWS credentials. For more information, see Configuring AWS Credentials in the AWS SDK for .NET Developer Guide.

  2. Write your code. For more information, see Programming with the AWS SDK for .NET.

    The following code excerpt creates the topic MyTopic and then prints the topic ARN and the CreateTopicRequest request ID.

    // Create an Amazon SNS topic. CreateTopicRequest createTopicRequest = new CreateTopicRequest("MyTopic"); CreateTopicResponse createTopicResponse = snsClient.CreateTopic(createTopicRequest); // Print the topic ARN. Console.WriteLine("TopicArn: " + createTopicResponse.TopicArn); // Print the request ID for the CreateTopicRequest action. Console.WriteLine("CreateTopicRequest: " + createTopicResponse.ResponseMetadata.RequestId);
  3. Compile and run your code.

    The topic is created and the topic ARN and CreateTopicRequest request ID are printed, for example:

    TopicArn: arn:aws:sns:us-east-2:123456789012:MyTopic CreateTopicRequest: 1234a567-bc89-012d-3e45-6fg7h890123i
  4. You can assign the topic ARN to a String variable to use in additional operations, for example:

    String topicArn = createTopicResponse.TopicArn;