This article provides a detailed overview of deleting SNS Subscriptions & Topics via using AWS Console & SDKs.


Delete SNS Subscriptions and Topics

  • It is possible to delete SNS subscription to a particular topic, or simply go with deleting the entire topic.
  • However, it is important to know that it’s not possible for you to delete subscriptions having the status of “Pending Confirmation”.
  • After 3 days & if still the subscription remains unconfirmed for your topic, then Amazon SNS will directly delete this topic with the unconfirmed subscription.
  • To learn how to subscribe to a topic check out our guide on how to get started with AWS SNS Topic Subscriptions.

How to Delete SNS Subscriptions and Topics? (AWS Management Console)

In order for you to delete SNS subscriptions with the Management Console, go through the below steps:

From the navigation pane, click on the option of Subscriptions.

Delete SNS Subscriptions - Subscriptions

Delete SNS Subscriptions – Subscriptions

  • From the page titled Subscriptions, pick a subscription having Confirmed as its Status, then click on the option Delete.
Delete SNS Subscriptions - Delete

Delete SNS Subscriptions – Delete

  • From the dialog box of Delete subscription, click on the option Delete.
  • Now, you will find that the console has deleted your selected subscription.
  • Whenever you choose to go with deleting a topic, you will find that Amazon SNS is going to delete this topic’s subscriptions as well.

In order for you to delete SNS topics with the Management Console, go through the below steps:

From the navigation pane, click on the option of Topics.

Delete SNS Subscriptions - Topics

Delete SNS Subscriptions – Topics

  • From the page titled Topics, pick a specific topic, then click on the option of Delete.
Delete SNS Subscriptions - Select and Delete

Delete SNS Subscriptions – Select and Delete

  • From the dialog box of Delete topic, type in “delete me”, then click on the option Delete.

    Delete SNS Subscriptions - Confirm Deletion

    Delete SNS Subscriptions – Confirm Deletion

  • Now, you will find that the console has deleted this topic.

How to delete SNS Subscriptions and Topics? (AWS SDK for Java)

In order for you to delete SNS subscriptions and topics using the AWS SDK for Java, you will have to go through the below steps:

  • Set your AWS credentials.
  • Type in your code.

Below is a code snipped which will delete a specific topic, then print the request ID of DeleteTopicRequest.

It’s Good to Know

Whenever a topic gets deleted, you are going to delete SNS subscriptions associated to this topic as well.

  • Here, we are deleting a specific Amazon SNS topic.

final DeleteTopicRequest deleteTopicRequest = new DeleteTopicRequest(topicArn);
snsClient.deleteTopic(deleteTopicRequest);

  • Here, we are printing the DeleteTopicRequest action’s request ID.
System.out.println("DeleteTopicRequest: " + snsClient.getCachedResponseMetadata(deleteTopicRequest));
  • Now, you should start with compiling and running your code.

Finally, you will find that the topic will be deleted and the request ID for DeleteTopicRequest will be printed, as shown in the below reference:

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

How to Delete SNS Subscriptions and Topics? (AWS SDK for .NET)

In order for you to delete SNS Subscriptions and Topics using the AWS SDK for .Net, go through the below steps:

  • Set your AWS credentials.
  • Type in your code.

Below is a code excerpt which will delete a specific topic, then print the request ID of DeleteTopicRequest.

It’s Good to Know

Upon deleting a topic, you are going to delete SNS subscriptions associated to this topic as well.

  • Here, we are deleting a specific Amazon SNS topic.
DeleteTopicRequest deleteTopicRequest = new DeleteTopicRequest(topicArn);
DeleteTopicResponse deleteTopicResponse = snsClient.DeleteTopic(deleteTopicRequest);
  • Here, we are printing the DeleteTopicRequest action’s request ID.
Console.WriteLine("DeleteTopicRequest: " + deleteTopicResponse.ResponseMetadata.RequestId);
  • Now, you should start with compiling and running your code.

Finally, you will find that the topic will be deleted and the request ID for DeleteTopicRequest will be printed, as shown in the below reference:

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

How to Configure tags for your Amazon SNS topics?

It’s possible to start tracking your Amazon SNS resources, such as the ones related to cost allocation etc. For example, you can add, list or remove metadata tags for your Amazon SNS topics.

Follow the below steps to learn how you can start listing, adding, and removing metadata tags for your Amazon SNS topics through the AWS Management Console:

  • Login to your Amazon SNS console.
  • From navigation panel, click on the option of Topics.
  • From the page of Topics, pick a specific topic and click on the option of Edit.
  • Open the section of Tags.

You will find a list of all of the tags added to this topic.

  • You can modify topic tags by doing one of the following options:
    • You can optionally add a tag by clicking on the option of Add tag, then typing in a Key and a Value.
    • You can remove a tag by clicking on the option of Remove tag located beside a key-value pair.
  • Click on the option of Save changes.

Follow the below steps to learn how you can start listing, adding, and removing metadata tags for your Amazon SNS topics through the AWS SDK for Java:

  • Set your AWS credentials.
  • Type in your code.
  • For list the added tags of a specific topic, enter the below code:
final ListTagsForResourceRequest listTagsForResourceRequest = new ListTagsForResourceRequest();listTagsForResourceRequest.setResourceArn(topicArn);final ListTagsForResourceResult listTagsForResourceResult = snsClient.listTagsForResource(listTagsForResourceRequest);System.out.println(String.format("ListTagsForResource: \tTags for topic %s are %s.\n",topicArn, listTagsForResourceResult.getTags()));
  • For adding tags or just updating the present value of tags, enter the below code:
final Tag tagTeam = new Tag();tagTeam.setKey("Team");tagTeam.setValue("Development");final Tag tagEnvironment = new Tag();tagEnvironment.setKey("Environment");tagEnvironment.setValue("Gamma");     final List<Tag> tagList = new ArrayList<>();tagList.add(tagTeam);tagList.add(tagEnvironment);     final TagResourceRequest tagResourceRequest = new TagResourceRequest();tagResourceRequest.setResourceArn(topicArn);tagResourceRequest.setTags(tagList);final TagResourceResult tagResourceResult = snsClient.tagResource(tagResourceRequest);
  • For removing a topic’s tag with the tag’s key, enter the below code:
final UntagResourceRequest untagResourceRequest = new UntagResourceRequest();untagResourceRequest.setResourceArn(topicArn);final List<String> tagKeyList = new ArrayList<>();tagKeyList.add("Team");untagResourceRequest.setTagKeys(tagKeyList);final UntagResourceResult untagResourceResult = snsClient.untagResource(untagResourceRequest);
  • Now, start compiling and running your code.

You will find that the existing tags will get listed, 2 will get added, and 1 will get removed from this topic.


Here are few awesome resources on AWS Services:
AWS S3 Bucket Details
AWS Glue Tags
AWS S3 File Explorer
AWS Budget Alerts
AWS Cost Optimization

  • CloudySave is an all-round one stop-shop for your organization & teams to reduce your AWS Cloud Costs by more than 55%.
  • Cloudysave’s goal is to provide clear visibility about the spending and usage patterns to your Engineers and Ops teams.
  • Have a quick look at CloudySave’s Cost Caluculator to estimate real-time AWS costs.
  • Sign up Now and uncover instant savings opportunities.

 


AUTHOR