c# - AWS SNS C# 无法发布大于 65kb 的消息

标签 c# amazon-web-services sdk signing amazon-sns

当我尝试在 C# 中使用 AWSSDK 版本 2.0.8.2 发布大于 65536 字节的消息时。

我得到以下异常:

An exception of type 'Amazon.SimpleNotificationService.Model.InvalidParameterException' occurred in AWSSDK.dll but was not handled in user code

Additional information: Invalid parameter: Message too long, only requests with signature version 4 can publish messages larger than 65536 bytes.

我到处都看过,包括 AWS 文档,但我找不到如何使用签名 4 进行 SNS 推送。有人知道吗?

我已经尝试更新到 2.0.10.0 但仍然没有成功,这是我正在使用的代码

RegionEndpoint regionEndPoint = RegionEndpoint.USWest2;

IAmazonSimpleNotificationService snsClient = AWSClientFactory.CreateAmazonSimpleNotificationServiceClient(awsAccessKeyId, awsSecretAccessKey, regionEndPoint);

PublishRequest publishRequest = new PublishRequest()
            {
                Subject = subject,
                Message = jsonBody,
                TopicArn = testTopicArn
            };

            snsClient.Publish(publishRequest);

最佳答案

AWS 于 2013 年 6 月 18 日在 SQS 和 SNS 中添加了对 256 kb 负载的支持,如本 AWS: "What's new?" 中所宣布的那样邮政。来自帖子:

256KB Payloads (SQS and SNS) enable developers to send and receive more data with each API call. Previously, payloads were capped at 64KB. Now, large payloads are billed as one request per 64KB 'chunk' of payload. For example, a single API call for a 256KB payload will be billed as four requests. Our customers tell us larger payloads will enable new use cases that were previously difficult to accomplish.

These features are available today in all regions. In order to use these features, you must use the latest SDK that has AWS Signature Version 4 enabled.

您应该只会收到该异常,因为您使用的是仅支持 64KB(65,536 字节)有效负载的旧版 SDK。不过,似乎 2.0.8 版本的 SDK 应该有这个签名。也许检查你在相关项目中的引用,也许你有对可能导致问题的旧版本的引用?

这是一些额外的 documentation关于 SNS 中的大负载。

关于c# - AWS SNS C# 无法发布大于 65kb 的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22134296/

相关文章:

c# - 将 Classes.FromCasSTLe Windsor 库的Assembly 迁移到 Autofac

amazon-web-services - 如何从 VPN 访问 AWS ElastiCache (Redis)

javascript - 将带有预签名 URL 的分段上传从 aws javascript sdk v2 迁移到 v3

java - 从本地地址检索联系人

c# - JSON 数组到 Entity Framework Core 非常慢?

c# - 无法在 DLL 'MediaInfo_New' 中找到名为 'MediaInfo.dll' 的入口点

c# - C# 中的 Des 和 3Des 以及 ecb(来自 C)

ios - iOS 后端

java - 如何获取 EC2 实例的 CloudWatch 指标数据

ios - swift LinkedIn 登录 : Get Public Profile URL