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

发布于 2024-09-29 22:59:08 字数 956 浏览 3 评论 0原文

尝试使用 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> 

When attempting to add permissions to an Amazon SNS topic using the AWS SDK for .NET/1.1.0.1 using code similar to the following:

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

The following error message is returned:

<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> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薔薇婲 2024-10-06 22:59:08

更新 - 此问题已在最新版本的 .NET API 中得到解决,因此仍然遇到此问题的任何人都应升级到 1.1.1 版本


我花了一段时间才弄清楚发生了什么,最终不得不使用 HTTP 版本的客户端以及 Wireshark< /a> 来观察发生了什么,但 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

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

目前,除了不在 .NET 应用程序中使用该命令并编写自己的代码来进行调用之外,似乎没有什么可以做的。如果幸运的话,这个问题将在 SDK 更新中得到解决。

Update - This has been resolved in the latest version of the .NET API so anyone still encountering this problem should upgrade to the 1.1.1 version of the API.


Took me awhile to figure out what was going on and I ended up having to use the HTTP version of the clients as well as Wireshark to watch what was happening, but it appears that there is a bug in AWS SDK for .NET/1.1.0.1. When I wrote a similar function using the AWS SDK for Java things proved to work fine, the following is a small block of that code:

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

Watching what was happening via Wireshark turned up the following, with some minor censoring and editing for clarity:

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

As you can see, the AWS SDK for .NET is making a call using AWSAccountIds and ActionNames as opposed to AWSAccountId and ActionName used by the AWS Java SDK which explains the error message that was returned.

For now there doesn't appear to be much that can be done about it short of not using the command in .NET applications and writing your own code to make the call. With any luck this will be fixed in an update to the SDK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文