dynamodb-lease
Client that acquires distributed locks in dynamodb that expire (aka "leases"). Uses aws-sdk-dynamodb & tokio.
let client = builder
.table_name
.lease_ttl_seconds
.build_and_check_db
.await?;
// acquire a lease for "important-job-123"
// waits for any other holders to release if necessary
let lease = client.acquire.await?;
// `lease` periodically extends itself in a background tokio task
// until dropped others will not be able to acquire this lease
assert!;
// Dropping the lease will asynchronously release it, so others may acquire it
drop;
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.
AWS setup
You may also need to setup some aws config, e.g.
- setup
~/.aws/config[default] region = eu-west-1 - setup
~/.aws/credentialswith fakes values[default] aws_access_key_id=12341234 aws_secret_access_key=12341234