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 Options
// With options callback
services.AddDynamoDb(options =>
{
options.Region = "us-east-1";
options.ServiceUrl = "http://localhost:8000"; // Local development
});
// From configuration
services.AddDynamoDb(configuration);
services.AddDynamoDb(configuration, sectionName: "DynamoDb");
// With pre-configured client
services.AddDynamoDbWithClient(dynamoDbClient);
Snapshot Store
services.AddDynamoDbSnapshotStore(options =>
{
options.TableName = "Snapshots";
});
Change Data Capture
services.AddDynamoDbCdc(options =>
{
options.StreamArn = "arn:aws:dynamodb:...";
});
services.AddDynamoDbCdcStateStore(options =>
{
options.TableName = "CdcState";
});
// In-memory state store for testing
services.AddInMemoryDynamoDbCdcStateStore();
Authorization Store
services.AddDynamoDbAuthorization(options =>
{
options.TableName = "AuthGrants";
});
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
- Data Providers Overview — Architecture and core abstractions
- Cosmos DB Provider — Azure cloud-native alternative
- Firestore Provider — Google Cloud alternative