使用.NET库时向Amazon SNS主题添加权限时出错

时间:2010-10-31 04:22:43

标签: c# .net amazon-sns

尝试使用类似于以下内容的代码使用AWS SDK for .NET / 1.1.0.1向Amazon SNS主题添加权限时:

AddPermissionRequest request = new AddPermissionRequest()
    .WithActionNames(new[] { "Publish" })
    .WithAWSAccountIds(new[] { "xxx" })
    .WithLabel("PrincipleAllowControl")
    .WithTopicArn(resourceName);
client.AddPermission(request); 

返回以下错误消息:

<ErrorResponse xmlns=" http://sns.amazonaws.com/doc/2010-03-31/">
  <Error>
    <Type>Sender</Type>
    <Code>ValidationError</Code>
    <Message>2 validation errors detected: Value null at 'actionName' failed to satisfy constraint: Member must not be null; Value null at 'aWSAccountId' failed to satisfy constraint: Member must not be null</Message>
  </Error>
  <RequestId>45054159-e46b-11df-9b30-693941920fe7</RequestId>
</ErrorResponse> 

1 个答案:

答案 0 :(得分:1)

在最新版本的.NET API中

更新 - This has been resolved,以便任何仍遇到此问题的人都应该升级到API的1.1.1 version


花了一些时间来弄清楚发生了什么,我最终不得不使用HTTP版本的客户端以及Wireshark来观察发生的事情,但似乎AWS中存在一个错误SDK for .NET / 1.1.0.1。当我使用AWS SDK for Java事件编写类似函数时,事实证明工作正常,以下是该代码的一小部分:

AddPermissionRequest permissionRequest = new AddPermissionRequest()
   .withActionNames("Publish")
   .withAWSAccountIds("xxx")
   .withLabel("PrincipleAllowControl")
   .withTopicArn(resourceName);
client.addPermission(permissionRequest); 

通过Wireshark观察发生的事情,发现了以下内容,为了清晰起见,进行了一些小的审查和编辑:

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
User-Agent: AWS Java SDK-1.0.14
Host: sns.us-east-1.amazonaws.com
Content-Length: 419

Action=AddPermission&
SignatureMethod=HmacSHA256&
Label=PrincipleAllowControl&
ActionName.member.1=Publish&
AWSAccessKeyId=xxx&
Version=2010-03-31&
AWSAccountId.member.1=xxx&
SignatureVersion=2&
TopicArn=arn%3Aaws%3Asns%3Aus-east-1%3A589983072084%3Axxx&
Timestamp=2010-10-31T02%3A10%3A10.833Z&
Signature=Bq09wa2vF1levQGcQZWVaix3UG7Mxlq2JCk4znEYHAM%3D

POST / HTTP/1.1
User-Agent: AWS SDK for .NET/1.1.0.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: sns.us-east-1.amazonaws.com
Content-Length: 422

Action=AddPermission&
TopicArn=arn%3Aaws%3Asns%3Aus-east-1%3A589983072084%3Axxx&
Label=PrincipleAllowControl&
AWSAccountIds.member.1=xxx&
ActionNames.member.1=Publish&
AWSAccessKeyId=xxx&
SignatureVersion=2&
SignatureMethod=HmacSHA256&
Timestamp=2010-10-30T21%3A18%3A39.753Z&
Version=2010-03-31&
Signature=m9OvL1v91eurDa5QYP9gwrd2crdtssHsDFonFny3frU%3D

如您所见,AWS SDK for .NET正在使用AWSAccountIds和ActionNames进行调用,而不是AWS Java SDK使用的AWSAccountId和ActionName,它解释了返回的错误消息。

目前,除了在.NET应用程序中不使用命令并编写自己的代码来进行调用之外,似乎没有太多可以做的事情。运气好的话,这将在SDK的更新中修复。