Skip to main content

Amazon DynamoDB Provider

The DynamoDB provider implements ICloudNativePersistenceProvider for AWS serverless workloads with hash/sort key support, DynamoDB Streams integration, and transactional batch operations.

Before You Start

  • .NET 8.0+ (or .NET 9/10 for latest features)
  • An AWS account with DynamoDB access
  • Familiarity with data access and IDb interface

Installation

dotnet add package Excalibur.Data.DynamoDb

Dependencies: Excalibur.Data.Abstractions, AWSSDK.DynamoDBv2

Quick Start

using Microsoft.Extensions.DependencyInjection;

services.AddDynamoDb(options =>
{
options.Region = "us-east-1";
options.TablePrefix = "MyApp_";
});

Registration Methods

MethodWhat It RegistersKey Options
AddDynamoDb(opts)Core persistence providerRegion, ServiceUrl, TablePrefix
AddDynamoDbWithClient(client)Provider with pre-configured clientN/A
AddDynamoDbSnapshotStore(opts)ISnapshotStoreTableName
AddDynamoDbAuthorization(opts)Authorization storeTableName

All methods also accept IConfiguration binding: AddDynamoDb(configuration, sectionName: "DynamoDb").

Change Data Capture

services.AddCdcProcessor(cdc =>
{
cdc.UseDynamoDb(dynamo =>
{
dynamo.TableName("Orders")
.StreamArn("arn:aws:dynamodb:...")
.WithStateStore(
sp => new AmazonDynamoDBClient(stateRegionEndpoint),
state => state.TableName("CdcState"));
})
.TrackTable("Orders", t => t.MapAll<OrderChangedEvent>())
.EnableBackgroundProcessing();
});

Partition and Sort Keys

DynamoDB uses hash keys and optional sort keys:

var key = new PartitionKey("USER#user-123", "/pk");
var result = await provider.GetByIdAsync<UserProfile>("PROFILE#main", key, consistencyOptions: null, cancellationToken: ct);

Batch Operations

Execute multiple operations atomically:

var batchResult = await provider.ExecuteBatchAsync(
partitionKey,
operations,
cancellationToken: ct);

See Also