- Newest
- Most votes
- Most comments
Everything mentioned in first answer stands valid, adding few recommendations with clarification:
SNS subscriptions are persistent — if your app is killed without unsubscribing, the subscription remains. AWS does not automatically clean them up. Messages will continue to be delivered (or retried until the endpoint is disabled), but the subscription object still exists.
Best practices:
- Make subscription logic idempotent (reuse existing subscriptions instead of creating duplicates).
- Periodically list and clean up unused subscriptions with Unsubscribe or DeleteTopic.
- Consider managing them via infrastructure-as-code for automatic lifecycle control.
When your application is forcibly terminated and cannot unsubscribe from an SNS topic properly, the subscription remains active in AWS. There are two scenarios to consider:
-
If the SNS topic continues to exist: The subscription will remain active indefinitely, and you'll need to manually delete it using the AWS Management Console or programmatically using an AWS SDK.
-
If the SNS topic is deleted: When a topic is deleted, its associated subscriptions are deleted asynchronously. The subscriptions enter a "Deleted" status but aren't immediately removed from your account. Amazon SNS will automatically remove these subscriptions after 48 hours. During this time, you cannot manually remove these subscriptions - you'll need to wait for the automatic cleanup process to complete.
For subscriptions that are pending confirmation (unconfirmed), Amazon SNS automatically deletes them after 48 hours regardless of the topic status.
To handle leaked subscriptions manually, you could implement a cleanup mechanism that tracks your application's subscriptions (perhaps storing subscription ARNs) and periodically checks for and removes any that shouldn't be active. You can use the AWS SDK to delete subscriptions by calling the unsubscribe method with the subscription ARN.
Sources
Deleting an Amazon SNS topic and subscription - Amazon Simple Notification Service
delete subscriptions in cloud watch | AWS re:Post
Use Unsubscribe with an AWS SDK or CLI - Amazon Simple Notification Service
Work with Amazon Simple Notification Service - AWS SDK for Java 2.x
Relevant content
asked 5 years ago
