1
votes

I'm writing an application that programmatically creates a new SQS queue that subscribes to an existing SNS topic and then deletes the SQS queue after.

I know there's a way to delete the SNS topic along with its subscriptions using Java SDK. I know I can manually delete the confirmed subscriptions from the web console. I know that pending subscriptions will expire on their own.

But I'd like to delete confirmed subscriptions programmatically but keep the SNS topic. Or will my confirmed subscription expire after some time after the SQS queue is gone?

1

1 Answers

1
votes

To delete a subscriber to an Amazon SNS topic using the Java SDK, you should use the unsubscribe() command.

default UnsubscribeResponse unsubscribe(Consumer<UnsubscribeRequest.Builder> unsubscribeRequest)
                                 throws InvalidParameterException,
                                        InternalErrorException,
                                        AuthorizationErrorException,
                                        NotFoundException,
                                        InvalidSecurityException,
                                        AwsServiceException,
                                        SdkClientException,
                                        SnsException

Deletes a subscription. If the subscription requires authentication for deletion, only the owner of the subscription or the topic's owner can unsubscribe, and an AWS signature is required. If the Unsubscribe call does not require authentication and the requester is not the subscription owner, a final cancellation message is delivered to the endpoint, so that the endpoint owner can easily resubscribe to the topic if the Unsubscribe request was unintended.