Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SNS Error Invalid parameter: Token Reason: Endpoint xxx already exists with the same Token, but different attributes

Using AWS SDK for iOS v2.0.8

Quick question:

How do I [snsClient deleteEndpoint:request], when I do not know this endpoint's arn? I do have the deviceToken.

Detail:

I am receiving the error Token Reason: Endpoint arn:aws:sns:...c6 already exists with the same Token, but different attributes when I attempt to create an endpoint for my iPhone:

// Async call to create the platform endpoint
[[[_awsSnsClient createPlatformEndpoint:request] continueWithSuccessBlock:^id(BFTask *task) {
    // success
    _awsPlatformEndpoint = task.result; // Save off the endpoint data
    [self awsUsubscribeAllSubscriptions];
    return nil;
}] continueWithBlock:^id(BFTask *task) {
    if (task.error) {
        // failed with error
        ALog(@"Error: Code:%li localizedDesc:%@ Exception:%@", (long)task.error.code, task.error.localizedDescription, task.exception);
        if(task.error.code == 7) {
            // delete offending endpoint and create it again?
        }
    }
    return nil;
}];

When I create the endpoint I do not set the attributes, I do set customUserData based on client data which can change. In the SDK docs for customUserData it says: Arbitrary user data to associate with the endpoint. Amazon SNS does not use this data. The data must be in UTF-8 format and less than 2KB.

When I delete the endpoint from the SNS console, I can get a new endpoint. So how do I deleteEndpoint, when I do not know this endpoint's arn? I can see the arn in the AWS logging, but not in the BFTask* error object.

I've seen the ruby solution at 19551067, but I do not see a way the read the message, the ruby example reads the message from the exception, task.exception == nil in my case. I received from AWS verbose logging:

Using AWS logging:

2014-10-01 06:48:54.489 myApp[1665:1345740] AWSiOSSDKv2 [Verbose] AWSURLResponseSerialization.m line:244 | -[AWSXMLResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body: [<ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
  <Error>
    <Type>Sender</Type>
    <Code>InvalidParameter</Code>
    <Message>Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-west-2:245211809793:endpoint/APNS_SANDBOX/myApp-Dev/7bxxx-xxxx-xxxx-xxxc6 already exists with the same Token, but different attributes.</Message>
  </Error>
  <RequestId>d874ac10-e6de-5a4d-805e-e0b6ee58e5b7</RequestId>
</ErrorResponse>
]

What I can get from (BFTask* task).error:

2014-10-01 06:48:54.494 myApp[1665:1345740] __46-[AppDelegate_Shared awsStartWithDeviceToken:]_block_invoke1279 [Line 3558] Error: 
  Code:7 
  localizedDesc:The operation couldn’t be completed. (com.amazonaws.AWSSNSErrorDomain error 7.)
  Exception:(null)

** Update 2014-10-01 **

My development iPad started doing this just after updating to iOS 8.0.2. I do add the version number into the customUserData - but Amazon SNS does not use this field... right?

** Update 2014-01-01 19:06 GMT-07:00 **

Added task.error.userInfo to the error block. I'll parse the message and delete the endpoint when this comes up. An option in AWSSNSCreatePlatformEndpointInput to override this error, update the endpoint and return the endpoint would be nice ;)

thank you!

Console now has:

2014-10-01 18:58:50.836 iFlightBag[1862:1493821] __46-[AppDelegate_Shared     awsStartWithDeviceToken:]_block_invoke1281 [Line 3559] Error: 
Code:7 
localDesc:The operation couldn’t be completed. (com.amazonaws.AWSSNSErrorDomain error 7.) 
Exception:(null) 
userInfo:{
    Code = InvalidParameter;
    Message = "Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-west-2:245211809793:endpoint/APNS_SANDBOX/LevelFlightMobile-Dev/7b70d2c4-846e-3afd-a1ba-eedaa00f7ac6 already exists with the same Token, but different attributes.";
    Type = Sender;
    "__text" =     (
        "\n    ",
        "\n    ",
        "\n    ",
        "\n  "
    );
}
like image 445
Kent Avatar asked Oct 01 '14 14:10

Kent


1 Answers

The userInfo property of task.error should contains a dictionary representation of the error XML.

like image 196
Yosuke Matsuda Avatar answered Sep 25 '22 10:09

Yosuke Matsuda