4

Have been working with the recently released SDK that has support for C# lambdas. I have an SNS topic setup that Lambda A publishes to. That all is working fine. Now I have Lambda B that is subscribed to that same topic. When I fire of Lambda A Lambda B is triggered and a JSON message is passed. The issue is I can't seem to get the JSON parsed to the Amazon.SimpleNotificationService.Util.Message type.

I have given this 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": {}
   }
  }
 ]
}

So I have tried to do this code (where messageText is of type "object" parameter which does give me just the "Sns" node.

var j = Newtonsoft.Json.Linq.JObject.Parse(messageText.ToString());
var sns = jsonData["Records"][0]["Sns"];

Console.Write($"sns object: {sns}");
var message = Message.ParseMessage(sns.ToString());

But the ParseMessage calls throws an error saying the SigningCertUrl field is null. I have written the JSON out to cloudwatch and I see all the fields are populated.

Where am I off track here? I thought the Lambda serializer might just parse the Message parameter for me but when I tried that all the properties where null.

2
  • What's the output of Console.Write($"sns object: {sns}");? Commented Dec 4, 2016 at 16:55
  • It holds the object value at the sns node of the larger object...... { "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": {} } Commented Dec 5, 2016 at 1:40

1 Answer 1

2

So the issue here is a bug in the AWS SDK for parsing the message. Here is what the "parseMessage" method is doing(there are some other fields too but these are the ones with issues). Note how the end is "URL" (all caps) instead of "Url"

  message.SigningCertURL = Message.ValidateCertUrl(func("SigningCertURL"));
  message.SubscribeURL = func("SubscribeURL");
  message.UnsubscribeURL = func("UnsubscribeURL");

Here is what is in the JSON

"SigningCertUrl": "<pem url here>",
"UnsubscribeUrl": "<unsub url here>",

So when the parse runs it finds no field so it returns null. Which makes the ValidateCertUrl method fail.

I verified this by just updating my JSON string to change from "URL" to "Url" and everything started working.

I have logged an issue on GitHub for this. https://github.com/aws/aws-sdk-net/issues/502

UPDATE If you look at the GitHub issue you will see the reason I ran into this was because I was using the wrong library. So not a bug, user error :(

Pull in this library. Amazon.Lambda.SNSEvents

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.