Skip to content

MarechJ/dynamodb-lock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dynamodb-lock

dynamodb-lock is based on https://github.com/joeabrams026/dynamo-lock, a node.js and dynamodb based locking client. It supports autoexpiring locks, spinning for a lock and manually releasing a lock. It's designed primarily for use in AWS Lambda code, but can be used elsewhere without modification.

It needs better docs, exception handling and testing, but the guts are currently there. Patches welcome!

Forked from: https://github.com/Elethiomel/dynamodb-lock

Install from pypi

pip3 install dynamo_lock

Usage

from dynamo_lock import LockerClient

lock = Lockerclient('mylocktable')

Or with credentials:

    lock = LockerClient(
        config.DYN_TABLE_NAME,
        config.DYN_ACCESS_KEY,
        config.DYN_SECRET_KEY
    )

If necessary, create the lock table.

lock.create_lock_table()

Attempt to aquire a lock. Returns True or False if succeeded.

lock_expiry_ms = 1000  # Milliseconds after which the lock expires
lock.acquire('mylock', lock_expiry_ms)

Alternatively, spin for a lock if locks are bound to be short lived and you can spare the cpu.

lock.spinlock('mylock', 10)

Finally, release your lock

lock.release('mylock', 10)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%