Tutorial: Deleting an Amazon SNS subscription and topic - Amazon Simple Notification Service

Tutorial: Deleting an Amazon SNS subscription and topic

When you no longer need a subscription or topic, you must first unsubscribe from the topic before you can delete the topic.

The following tutorial shows how you can use the AWS Management Console, the AWS SDK for Java, and the AWS SDK for .NET to subscriptions and topics.

To delete an Amazon SNS subscription and topic using the AWS Management Console

  1. Sign in to the Amazon SNS console.

  2. On the navigation panel, choose Subscriptions.

  3. On the Subscriptions page, choose a confirmed subscription and then choose Delete.

    Note

    You can't delete a pending confirmation. After 3 days, Amazon SNS deletes it automatically.

  4. In the Delete subscription dialog box, choose Delete.

    The subscription is deleted.

  5. On the navigation panel, choose Topics.

  6. On the Topics page, choose a topic and then choose Delete.

    Important

    When you delete a topic, you also delete all subscriptions to the topic.

  7. On the Delete topic MyTopic dialog box, enter delete me and then choose Delete.

    The topic is deleted.

To delete an Amazon SNS subscription and 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 deletes a topic and then prints the DeleteTopicRequest request ID.

    Important

    When you delete a topic, you also delete all subscriptions to the topic.

    // Delete an Amazon SNS topic. final DeleteTopicRequest deleteTopicRequest = new DeleteTopicRequest(topicArn); snsClient.deleteTopic(deleteTopicRequest); // Print the request ID for the DeleteTopicRequest action. System.out.println("DeleteTopicRequest: " + snsClient.getCachedResponseMetadata(deleteTopicRequest));
  3. Compile and run your code.

    The topic is deleted and the DeleteTopicRequest request ID is printed, for example:

    DeleteTopicRequest: 1234a567-bc89-012d-3e45-6fg7h890123i

To delete an Amazon SNS subscription and 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 deletes a topic and then prints the DeleteTopicRequest request ID.

    Important

    When you delete a topic, you also delete all subscriptions to the topic.

    // Delete an Amazon SNS topic. DeleteTopicRequest deleteTopicRequest = new DeleteTopicRequest(topicArn); DeleteTopicResponse deleteTopicResponse = snsClient.DeleteTopic(deleteTopicRequest); // Print the request ID for the DeleteTopicRequest action. Console.WriteLine("DeleteTopicRequest: " + deleteTopicResponse.ResponseMetadata.RequestId);
  3. Compile and run your code.

    The topic is deleted and the DeleteTopicRequest request ID is printed, for example:

    DeleteTopicRequest: 1234a567-bc89-012d-3e45-6fg7h890123i