https://github.com/alexheretic/dynamodb-lease
Dynamodb distributed lock client for Rust
https://github.com/alexheretic/dynamodb-lease
Last synced: 3 days ago
JSON representation
Dynamodb distributed lock client for Rust
- Host: GitHub
- URL: https://github.com/alexheretic/dynamodb-lease
- Owner: alexheretic
- License: apache-2.0
- Created: 2023-09-25T18:02:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-18T18:06:48.000Z (11 days ago)
- Last Synced: 2025-04-19T06:30:56.370Z (10 days ago)
- Language: Rust
- Size: 51.8 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# dynamodb-lease
Client that acquires distributed locks in dynamodb that expire (aka "leases").
Uses [aws-sdk-dynamodb](https://github.com/awslabs/aws-sdk-rust/tree/main/sdk/dynamodb)
& [tokio](https://github.com/tokio-rs/tokio).[](https://crates.io/crates/dynamodb-lease)
[](https://docs.rs/dynamodb-lease)```rust
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](./DESIGN.md) & source for how it works under the hood.
## Test
Run `scripts/init-test.sh` to ensure dynamodb-local is running on 8000.```sh
cargo test
```### AWS setup
You may also need to setup some aws config, e.g.
- setup `~/.aws/config`
```
[default]
region = eu-west-1
```
- setup `~/.aws/credentials` with fakes values
```
[default]
aws_access_key_id=12341234
aws_secret_access_key=12341234
```