Skip to content

mguinness/SnsWebHook

Repository files navigation

Webhook support for Amazon SNS in ASP.NET Core

Accept inbound Amazon SNS notification messages.

Configuring Project

  1. Add SnsWebHook NuGet package into your project
  2. Modify your ConfigureServices method in Startup.cs file
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
      .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
      .AddSnsWebHooks();
}
  1. 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);
        }
    }
}

Configuring Webhook

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.

About

Webhook support for Amazon SNS in ASP.NET Core

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages