Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 解析AWS Lambda的SNS消息对象_C#_Aws Lambda_Amazon Sns - Fatal编程技术网

C# 解析AWS Lambda的SNS消息对象

C# 解析AWS Lambda的SNS消息对象,c#,aws-lambda,amazon-sns,C#,Aws Lambda,Amazon Sns,一直在使用最近发布的SDK,该SDK支持C#lambdas。我有一个SNS主题设置,Lambda A发布给我。一切正常。现在我有Lambda B订阅了同一主题。当我触发Lambda时,会触发Lambda B并传递一条JSON消息。问题是我似乎无法将JSON解析为Amazon.SimpleNotificationService.Util.Message类型 我已经给出了这个JSON { "Records": [ { "EventSource": "aws:sns", "EventVersi

一直在使用最近发布的SDK,该SDK支持C#lambdas。我有一个SNS主题设置,Lambda A发布给我。一切正常。现在我有Lambda B订阅了同一主题。当我触发Lambda时,会触发Lambda B并传递一条JSON消息。问题是我似乎无法将JSON解析为Amazon.SimpleNotificationService.Util.Message类型

我已经给出了这个JSON

{
"Records": [
{
  "EventSource": "aws:sns",
  "EventVersion": "1.0",
  "EventSubscriptionArn": "arn:.......",
  "Sns": {
    "Type": "Notification",
    "MessageId": "ce4a1d7c-c50d-51ea-bfe8-4dc1078795fe",
    "TopicArn": "arn:.......",
    "Subject": null,
    "Message": "test queue",
    "Timestamp": "2016-12-04T07:05:46.709Z",
    "SignatureVersion": "1",
    "Signature": "<mysighere>",
    "SigningCertUrl": "<pem url here>",
    "UnsubscribeUrl": "<unsub url here>",
    "MessageAttributes": {}
   }
  }
 ]
}
但是ParseMessage调用抛出一个错误,指出SigningCertUrl字段为空。我已经将JSON写入cloudwatch,我看到所有字段都已填充


我在哪里偏离了轨道?我认为Lambda序列化程序可能只是为我解析消息参数,但当我尝试解析时,所有属性都为null

因此,这里的问题是AWS SDK中用于解析消息的错误。下面是“parseMessage”方法正在做的事情(还有一些其他字段,但这些字段有问题)。注意结尾是“URL”(所有大写)而不是“URL”

以下是JSON中的内容

"SigningCertUrl": "<pem url here>",
"UnsubscribeUrl": "<unsub url here>",
“SigningCertUrl”:“,
“取消订阅URL”:“,
因此,当解析运行时,它找不到字段,因此返回null。这使得ValidateCertUrl方法失败

我通过更新JSON字符串将“URL”更改为“URL”来验证这一点,然后一切都开始工作

为此,我在GitHub上记录了一个问题。

更新 如果你看一下GitHub的问题,你会发现我遇到这个问题的原因是因为我使用了错误的库。所以不是bug,用户错误:(

拉进这个图书馆。
Amazon.Lambda.SNSEvents

Console.Write($“sns对象:{sns}”);?它在较大对象的sns节点上保存对象值……{“类型”:“通知”,“消息ID”:“ce4a1d7c-c50d-51ea-bfe8-4dc1078795fe”,“主题:”null,“消息”:“测试队列”,“时间戳”:“2016-12-04T07:05:46.709Z”,“SignatureVersion:“1”,“Signature:”“SigningCertUrl:”“UnsubscribeUrl:”“MessageAttributes:{}”
  message.SigningCertURL = Message.ValidateCertUrl(func("SigningCertURL"));
  message.SubscribeURL = func("SubscribeURL");
  message.UnsubscribeURL = func("UnsubscribeURL");
"SigningCertUrl": "<pem url here>",
"UnsubscribeUrl": "<unsub url here>",