AWS SNS HTTP POST to C# (dotnet core 2.1)

I spent way too much time on this today and I wanted to document what I found and a simple work around for what seems to be an oversight on AWS’ part.  (read some forums and you’ll see the threads)

When setting up an SNS Topic for instance when you have two services (APIs) that you want to connect together, you need to first confirm that the subscriber to can handle the messages. The part that took me forever to get (it is documented as such) but when looking at JSON messages all day, you don’t pay attention to the header.

Here is the link to the setup article

Section 1.  Notice that there is a sample payload for what you might expect.  The tip for you is to pay attention to the Content-Type in the header.  Although that body in the POST is JSON, they are sending it as text/plain.

And when using C#, having JSON as a parameter in [FromBody] is a no brainer with the serialization into your object happening automatically. However, with text/plain, C# doesn’t know what to do with the input.  The below method is just an approach to dealing with this.  I’m going to wrap this up at some point soon and create a custom InputFormatter which I’ll post once I get that done.  For now, the below code will get you going.  Best of luck and I hope this saves you some time!


Leave a Reply

Your email address will not be published. Required fields are marked *