DynamoDb.DistributedLock
1.0.0.6
See the version list below for details.
dotnet add package DynamoDb.DistributedLock --version 1.0.0.6
NuGet\Install-Package DynamoDb.DistributedLock -Version 1.0.0.6
<PackageReference Include="DynamoDb.DistributedLock" Version="1.0.0.6" />
<PackageVersion Include="DynamoDb.DistributedLock" Version="1.0.0.6" />
<PackageReference Include="DynamoDb.DistributedLock" />
paket add DynamoDb.DistributedLock --version 1.0.0.6
#r "nuget: DynamoDb.DistributedLock, 1.0.0.6"
#:package DynamoDb.DistributedLock@1.0.0.6
#addin nuget:?package=DynamoDb.DistributedLock&version=1.0.0.6
#tool nuget:?package=DynamoDb.DistributedLock&version=1.0.0.6
๐ DynamoDb.DistributedLock
DynamoDb.DistributedLock is a lightweight .NET library for distributed locking using Amazon DynamoDB. It is designed for serverless and cloud-native applications that require coordination across services or instances.
- โ Safe and atomic lock acquisition using conditional writes
- โ TTL-based expiration to prevent stale locks
- โ AWS-native, no external infrastructure required
- โ
Simple
IDynamoDbDistributedLock
interface - โ Tested and production-ready for .NET 8 and 9
๐ฆ Package
Package | Build | NuGet | Downloads |
---|---|---|---|
DynamoDb.DistributedLock |
๐ Getting Started
1. Install the NuGet package
dotnet add package DynamoDb.DistributedLock
2. Register the lock in your DI container
services.AddDynamoDbDistributedLock(options =>
{
options.TableName = "my-lock-table";
options.LockTimeoutSeconds = 30;
options.PartitionKeyAttribute = "pk";
options.SortKeyAttribute = "sk";
});
Or bind from configuration:
services.AddDynamoDbDistributedLock(configuration);
appsettings.json
{
"DynamoDbLock": {
"TableName": "my-lock-table",
"LockTimeoutSeconds": 30,
"PartitionKeyAttribute": "pk",
"SortKeyAttribute": "sk"
}
}
3. Use the lock
public class MyService(IDynamoDbDistributedLock distributedLock)
{
public async Task<bool> TryDoWorkAsync()
{
var acquired = await distributedLock.AcquireLockAsync("resource-1", "owner-abc", CancellationToken.None);
if (!acquired) return false;
try
{
// ๐ง Critical section
}
finally
{
await distributedLock.ReleaseLockAsync("resource-1", "owner-abc", CancellationToken.None);
}
return true;
}
}
๐๏ธ Table Schema
This library supports both dedicated tables and shared, single-table designs. You do not need to create a separate table just for locking โ this works seamlessly alongside your existing entities.
By default, the library uses the following attributes:
- Partition key:
pk
(String) - Sort key:
sk
(String) - TTL attribute:
expiresAt
(Number, UNIX timestamp in seconds)
However, the partition and sort key attribute names are fully configurable via DynamoDbLockOptions
. This makes it easy to integrate into your existing table structure.
โ Enable TTL on the expiresAt field in your table settings to allow automatic cleanup of expired locks.
๐งช Unit Testing
Unit tests are written with:
- โ xUnit v3
- โ AutoFixture + NSubstitute
- โ FluentAssertions (AwesomeAssertions)
The library provides DynamoDbDistributedLockAutoData
to support streamlined tests with frozen mocks and null-value edge cases.
๐ฎ Future Enhancements
- โ๏ธ Configurable partition/sort key field names
- โฑ Lock renewal support
- ๐ Auto-release logic for expired locks
- ๐ Metrics and diagnostics support
๐ License
MIT
This project is licensed under the MIT License. See the LICENSE file for details.
๐ค Contributing
Contributions, feedback, and GitHub issues welcome!
Product | Versions 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 is compatible. 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. |
-
net8.0
- AWSSDK.DynamoDBv2 (>= 4.0.1)
- AWSSDK.Extensions.NETCore.Setup (>= 4.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.5)
- Microsoft.Extensions.DependencyInjection (>= 9.0.5)
- Microsoft.Extensions.Options (>= 9.0.5)
-
net9.0
- AWSSDK.DynamoDBv2 (>= 4.0.1)
- AWSSDK.Extensions.NETCore.Setup (>= 4.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.5)
- Microsoft.Extensions.DependencyInjection (>= 9.0.5)
- Microsoft.Extensions.Options (>= 9.0.5)
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.1.2.14 | 91 | 8/14/2025 |
1.1.1.13 | 382 | 7/25/2025 |
1.1.0.12 | 168 | 6/23/2025 |
1.1.0.11 | 291 | 6/10/2025 |
1.1.0.10 | 101 | 6/6/2025 |
1.1.0-beta.9 | 75 | 6/6/2025 |
1.1.0-beta.8 | 72 | 6/6/2025 |
1.1.0-beta.7 | 78 | 6/6/2025 |
1.0.0.6 | 156 | 5/21/2025 |
1.0.0.5 | 155 | 5/19/2025 |
1.0.0.2 | 193 | 5/16/2025 |
1.0.0.1 | 229 | 5/15/2025 |
1.0.0-beta.4 | 120 | 5/19/2025 |