Process DynamoDB Streams events in AWS Lambda with high performance and native AOT support. This package provides a streamlined way to handle DynamoDB change data capture events, supporting both single-record and batch processing patterns with built-in error handling and integration with the Goa DynamoDB mapper for seamless object deserialization.
dotnet new install Goa.Templates
dotnet new goa.dynamodb -n "MyDynamoFunction"- Flexible Processing Modes: Choose between processing records one at a time or as a batch
- DynamoDB Mapper Integration: Seamlessly deserialize DynamoDB records to strongly-typed objects
- Stream Event Support: Handle INSERT, MODIFY, and REMOVE operations from DynamoDB Streams
- Native AOT Ready: Optimized for ahead-of-time compilation with minimal cold starts
- Error Handling: Built-in support for marking individual records as failed for partial batch failures
- Dependency Injection: Full integration with .NET's dependency injection container
- Type-Safe: Strongly-typed stream records with full IntelliSense support
using Goa.Functions.Core;
using Goa.Functions.Dynamo;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json.Serialization;
await Host.CreateDefaultBuilder()
.UseLambdaLifecycle()
.ForDynamoDB()
.ProcessOneAtATime()
.HandleWith<IMyService>(async (service, record) =>
{
// Process each DynamoDB stream record if (record.EventName == DynamoStreamOperation.INSERT)
{
// DynamoMapper.MyItem is generated by the source generator
var item = DynamoMapper.MyItem.FromDynamoRecord(record.Dynamodb!.NewImage!);
await service.ProcessNewItem(item);
}
})
.WithServices(services =>
{
// Register your services
services.AddScoped<IMyService, MyService>();
})
.RunAsync();
// Define your model with DynamoDB attributes for source generation
[DynamoModel(PK = "ITEM#<Id>", SK = "META")]
public record MyItem(string Id, string Name, DateTime CreatedAt);
public interface IMyService
{
Task ProcessNewItem(MyItem item);
}For more information and examples, visit the main Goa documentation.