2013-10-23 18 views
8

Amazon SNS用Amazon AWS Ruby SDKを使用していますが、既に登録されているデバイスに問題があります。デバイスが再び登録されると、AWS::SNS::Errors::InvalidParameter Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-1:**** already exists with the same Token, but different attributes.のようなエラーが発生することがあります。エンドポイントがすでに存在しているかどうかを確認する方法、さらに重要なことは、特定のトークンのエンドポイントを取得する方法です。モバイルデバイスが既に登録されているかどうかを確認する方法

+0

node.jsにSNSと同じ問題があります。あなたはこれにいくつかの解決策を見つけましたか? –

+0

.net libを使用していますが、再度登録しようとするとエラーが発生しません。 –

+0

登録に関連する追加属性を保存し、後で別のセット属性の –

答えて

10

BvdBijlのアイデアを借りて、見つかった場合は既存のものを削除して追加する拡張メソッドを作成しました。

using System; 
using System.Text.RegularExpressions; 
using Amazon.SimpleNotificationService; 
using Amazon.SimpleNotificationService.Model; 

namespace Amazon.SimpleNotificationService 
{ 
    public static class AmazonSimpleNotificationServiceClientExtensions 
    { 
     private const string existingEndpointRegexString = "Reason: Endpoint (.+) already exists with the same Token"; 
     private static Regex existingEndpointRegex = new Regex(existingEndpointRegexString); 
     public static CreatePlatformEndpointResponse CreatePlatformEndpointIdempotent(
      this AmazonSimpleNotificationServiceClient client, 
      CreatePlatformEndpointRequest request) 
     { 
      try 
      { 
       var result = client.CreatePlatformEndpoint(request); 
       return result; 
      } 
      catch (AmazonSimpleNotificationServiceException e) 
      { 
       if (e.ErrorCode == "InvalidParameter") 
       { 
        var match = existingEndpointRegex.Match(e.Message); 
        if (match.Success) { 
         string arn = match.Groups[1].Value; 
         client.DeleteEndpoint(new DeleteEndpointRequest 
         { 
          EndpointArn = arn, 
         }); 
         return client.CreatePlatformEndpoint(request); 
        } 
       } 
       throw; 
      } 
     } 
    } 
} 
+3

これは文字通り私が見ることができる唯一の方法ですそれだけでなく。代わりに、あなただけ呼び出すことができます削除し、プラットフォームのエンドポイントを作成する – chadkouse

+2

: SetEndpointAttributes を属性 '有効= true'に – Kamil

+0

では、将来変更される可能性があり、エラーメッセージのうち、これを解析する必要が不思議な感じ。私たちに重複したエンドポイントを戻すだけではないというばかげたことがあります。 – user3344977

0

これはamazoneがこの問題を解決したようです。私はRoRのを使用して登録しようとGCMのコードを既存のときに、同じ問題を抱えているために使用しています 私は属性と同じ(空の)使用が

"AWS::SNS::Errors::InvalidParameter Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-1:**** already exists with the same Token, but different attributes." 

というエラーメッセージが表示されました。現在、既存のGCMコード(元の属性と同じ属性)を送信すると、エラーメッセージではなく、エンドポイントarnが取得されます。

0

ListEndpointsByPlatformApplicationは100個のエンドポイントしか返しません。さらに取得するにはnextTokenを使用する必要があります。ここに私の実装があります。

public void deleteEndpoint(string token, string PlatformApplicationArn) 
    { 
     ListEndpointsByPlatformApplicationRequest listRequest = new ListEndpointsByPlatformApplicationRequest(); 
     listRequest.PlatformApplicationArn = PlatformApplicationArn; 
     Logger.Info("Deleting endpoint with token -> " + token); 
     var list = snsClient.ListEndpointsByPlatformApplication(listRequest); 
     do 
     { 
      foreach (var x in list.Endpoints.Where(x => x.Attributes["Token"] == token)) 
      { 
       snsClient.DeleteEndpoint(new DeleteEndpointRequest() { EndpointArn = x.EndpointArn }); 
       Logger.Info("Endpoint removed-> " + x.EndpointArn); 
       return; 
      } 

      listRequest.NextToken = list.NextToken; 
      list = snsClient.ListEndpointsByPlatformApplication(listRequest); 
     } 
     while (list.NextToken != null); 

    } 
+0

私は多くの終点が1ラフを意味すると考えると、このプロセスでは、合計エンドポイントでトークンをチェックするために何らかの遅延が発生します。処理なしでエンドポイントを直接削除する方法はありますか? –

関連する問題