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.
。エンドポイントが既に存在するかどうかを確認するにはどうすればよいですか? さらに重要なことに、特定のトークンのエンドポイントを取得するにはどうすればよいですか?
4363 次
3 に答える
13
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;
}
}
}
}
于 2013-11-05T10:50:55.867 に答える
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 が表示されます。
于 2014-10-02T13:21:34.513 に答える
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);
}
于 2015-08-27T01:03:46.213 に答える