How to get Subscription ARN from Amazon SNS in order to unsubscribe from it
I'm using Amazon SNS and Cognito to subscribe and unsubscribe from topics certain devices.
*Note that there may be a similar topic, but Amazon no longer use that clases.
So far, so good...
But in order to unsubscribe a device from a topic, I need to pass the Subscription ARN which I'm unable to figure out within the App.
The Subscription ARN is made by the topic ARN (that I know) and an alphanumeric string that is generated by Amazon (that I don't know).
This code:
AWSSNSUnsubscribeInput *input = [[AWSSNSUnsubscribeInput alloc] init];
input.subscriptionArn = @"arn:aws:sns:XXXXXXXX-YYYYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZ";
NSLog(@"Input subscription: %@", input.subscriptionArn);
[sns unsubscribe: input completionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error occurred: [%ld]", error.code);
}
else {
NSLog(@"Success");
}
}];
It works fine if I get the Subscription ARN from the AWS console, but down in the App I have no possible way of querying or generate that field.
I guess there's a walk-around, but so far I was unable to get any successful approach. How should I proceed to get this done?
Thank you all very much.
With the topic ARN call [sns listSubscriptionsByTopic: input]
. The response will have a list of all the subscriptions for that topic, including the subscription ARN. You'll have to use the owner
property on the response to find the specific subscription to pass to unsubscribe
.
Something that I finally came with:
The "ListSubscriptions" or "ListSubscriptionsByTopic" API operations should return the subscription ARN:
http://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptions.html http://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptionsByTopic.html
链接地址: http://www.djcxy.com/p/5526.html