'AWS SnsClient.deleteTopic doesn't delete subscriptions

When I use the java SNS lib provided by AWS and I use the function

DeleteTopicResponse deleteTopic(DeleteTopicRequest deleteTopicRequest)

I expect the Topic to be deleted (which it does) and all the Subscriptions to be deleted as well (which it doesn't)

Having ran this application for a while, we found many 'floating' subscriptions in AWS.

The documentation of deleteTopic

Gives me the impression that it should delete all subscriptions

Deletes a topic and all its subscriptions. Deleting a topic might prevent some messages previously sent to the topic from being delivered to subscribers. This action is idempotent, so deleting a topic that does not exist does not result in an error.

Any insight on why there are Subscriptions without a Topic in our SNS?

Is this a bug? or am misunderstanding this method?

How can this be avoided?

Deleting all subscriptions manually might be a strain on the system, so if possible I would like to avoid that



Solution 1:[1]

According to https://aws.amazon.com/premiumsupport/knowledge-center/sns-cannot-delete-topic-subscription/:

Note: After three days, Amazon SNS automatically removes subscriptions that are in the Deleted and Pending Confirmation status from your account.

This should include the subscriptions associated with the deleted topic.

Note that you may run into issues recreating the subscription if you try to use the same topic name and endpoint before the previous one was deleted.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bjrnt