AWS.Lambda.Powertools.EventHandler 1.0.0

Prefix Reserved
dotnet add package AWS.Lambda.Powertools.EventHandler --version 1.0.0
                    
NuGet\Install-Package AWS.Lambda.Powertools.EventHandler -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AWS.Lambda.Powertools.EventHandler" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AWS.Lambda.Powertools.EventHandler" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AWS.Lambda.Powertools.EventHandler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AWS.Lambda.Powertools.EventHandler --version 1.0.0
                    
#r "nuget: AWS.Lambda.Powertools.EventHandler, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=AWS.Lambda.Powertools.EventHandler&version=1.0.0
                    
Install AWS.Lambda.Powertools.EventHandler as a Cake Addin
#tool nuget:?package=AWS.Lambda.Powertools.EventHandler&version=1.0.0
                    
Install AWS.Lambda.Powertools.EventHandler as a Cake Tool

AWS Lambda Powertools for .NET - Event Handler

Event Handler for AWS AppSync real-time events.

Key Features

  • Easily handle publish and subscribe events with dedicated handler methods
  • Automatic routing based on namespace and channel patterns
  • Support for wildcard patterns to create catch-all handlers
  • Process events in parallel or sequentially
  • Control over event aggregation for batch processing
  • Graceful error handling for individual events

Terminology

AWS AppSync Events{target="_blank"}. A service that enables you to quickly build secure, scalable real-time WebSocket APIs without managing infrastructure or writing API code. It handles connection management, message broadcasting, authentication, and monitoring, reducing time to market and operational costs.

Getting Started

  1. Install the NuGet package:
dotnet add package AWS.Lambda.Powertools.EventHandler --version 1.0.0
  1. Add the AWS.Lambda.Powertools.EventHandler namespace to your Lambda function:
using AWS.Lambda.Powertools.EventHandler;
  1. Update the AWS Lambda handler to use AppSyncEventsResolver
async Task<AppSyncEventsResponse> Handler(AppSyncEventsRequest appSyncEvent, ILambdaContext context)
{
    return await app.ResolveAsync(appSyncEvent, context);
}

Example

using AWS.Lambda.Powertools.EventHandler;
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;
using AWS.Lambda.Powertools.EventHandler.AppSyncEvents;
using AWS.Lambda.Powertools.Logging;

var app = new AppSyncEventsResolver();

app.OnPublishAsync("/default/channel", async (payload) =>
{
    Logger.LogInformation("Published to /default/channel with {@payload}", payload);

    if (payload["eventType"].ToString() == "data_2")
    {
        throw new Exception("Error in /default/channel");
    }

    return "Hello from /default/channel";
});

app.OnPublishAggregateAsync("/default/channel2", async (payload) =>
{
    var evt = new List<AppSyncEvent>();
    foreach (var item in payload.Events)
    {
        var pd = new AppSyncEvent
        {
            Id = item.Id,
            Payload = new Dictionary<string, object>
            {
                { "demo", "demo" }
            }
        };

        if (item.Payload["eventType"].ToString() == "data_2")
        {
            pd.Payload["message"] = "Hello from /default/channel2 with data_2";
            pd.Payload["data"] = new Dictionary<string, object>
            {
                { "key", "value" }
            };
        }

        evt.Add(pd);
    }

    Logger.LogInformation("Published to /default/channel2 with {@evt}", evt);
    return new AppSyncEventsResponse
    {
        Events = evt
    };
});

app.OnSubscribeAsync("/default/*", async (payload) =>
{
    Logger.LogInformation("Subscribed to /default/* with {@payload}", payload);
    return true;
});

async Task<AppSyncEventsResponse> Handler(AppSyncEventsRequest appSyncEvent, ILambdaContext context)
{
    return await app.ResolveAsync(appSyncEvent, context);
}

await LambdaBootstrapBuilder.Create((Func<AppSyncEventsRequest, ILambdaContext, Task<AppSyncEventsResponse>>)Handler,
new DefaultLambdaJsonSerializer())
        .Build()
        .RunAsync();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 159 4/24/2025