Accept inbound Amazon SNS notification messages.
- Add SnsWebHook NuGet package into your project
- Modify your
ConfigureServices
method inStartup.cs
file
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddSnsWebHooks();
}
- Add Controller class with
[SnsWebHook]
attribute
public class SnsController : ControllerBase
{
[SnsWebHook]
public async Task<IActionResult> SnsHandler(string @event, JObject data)
{
if (ModelState.IsValid)
{
Console.WriteLine(data.Value<string>("Message"));
if (@event == "SubscriptionConfirmation")
{
var url = data.Value<string>("SubscribeURL");
var response = await new HttpClient().GetAsync(url);
}
else
{
Console.WriteLine("Type {0} with payload {1}", @event, data);
}
return NoContent();
}
else
{
return BadRequest(ModelState);
}
}
}
See instructions for Getting Started with Amazon SNS on Amazon.
The callback address will be https://server/api/webhooks/incoming/sns and you'll need to replace server with your host.