Crates.io | dynamodb-lease |
lib.rs | dynamodb-lease |
version | 0.22.0 |
source | src |
created_at | 2022-10-24 09:14:05.131098 |
updated_at | 2023-11-26 13:03:57.790737 |
description | Dynamodb distributed lock client |
homepage | |
repository | https://github.com/alexheretic/dynamodb-lease |
max_upload_size | |
id | 695736 |
size | 52,302 |
Client that acquires distributed locks in dynamodb that expire (aka "leases"). Uses aws-sdk-dynamodb & tokio.
let client = dynamodb_lease::Client::builder()
.table_name("example-leases")
.lease_ttl_seconds(60)
.build_and_check_db(dynamodb_client)
.await?;
// acquire a lease for "important-job-123"
// waits for any other holders to release if necessary
let lease = client.acquire("important-job-123").await?;
// `lease` periodically extends itself in a background tokio task
// until dropped others will not be able to acquire this lease
assert!(client.try_acquire("important-job-123").await?.is_none());
// Dropping the lease will asynchronously release it, so others may acquire it
drop(lease);
See the design doc & source for how it works under the hood.
Run scripts/init-test.sh
to ensure dynamodb-local is running on 8000.
cargo test
You may also need to setup some aws config, e.g.
~/.aws/config
[default]
region = eu-west-1
~/.aws/credentials
with fakes values
[default]
aws_access_key_id=12341234
aws_secret_access_key=12341234