14 breaking releases

0.22.0 Nov 26, 2023
0.20.0 Nov 10, 2023
0.15.0 May 26, 2023
0.12.0 Jan 27, 2023
0.9.0 Oct 27, 2022

#2 in #dynamo-db

Download history 37/week @ 2023-11-05 24/week @ 2023-11-12 43/week @ 2023-11-19 92/week @ 2023-11-26 26/week @ 2023-12-03 18/week @ 2023-12-10 40/week @ 2023-12-24 15/week @ 2023-12-31 2/week @ 2024-01-21 39/week @ 2024-01-28 17/week @ 2024-02-04 59/week @ 2024-02-11 302/week @ 2024-02-18

417 downloads per month

MIT/Apache

23KB
383 lines

dynamodb-lease

Client that acquires distributed locks in dynamodb that expire (aka "leases"). Uses aws-sdk-dynamodb & tokio.

Crates.io Docs.rs

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.

Test

Run scripts/init-test.sh to ensure dynamodb-local is running on 8000.

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
    

Dependencies

~14–26MB
~346K SLoC