https://github.com/mashiike/setddblock
Distributed locking using Amazon DynamoDB
https://github.com/mashiike/setddblock
Last synced: about 1 month ago
JSON representation
Distributed locking using Amazon DynamoDB
- Host: GitHub
- URL: https://github.com/mashiike/setddblock
- Owner: mashiike
- License: mit
- Created: 2021-11-08T13:40:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T20:12:14.000Z (about 1 year ago)
- Last Synced: 2025-04-30T07:05:00.199Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 83 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# setddblock


[](https://goreportcard.com/report/mashiike/setddblock)
[](https://github.com/mashiike/setddblock/blob/master/LICENSE)
[](https://godoc.org/github.com/mashiike/setddblock)setddblock is setlock like command line tool with [AWS DynamoDB](https://aws.amazon.com/dynamodb/)
## Usage
```console
$ setddblock -xN ddb://ddb_lock_table/lock_item_id your_command
``````console
Usage: setddblock [ -nNxX ] [--endpoint ] [--debug --version] ddb:/// your_command
Flags:
-n
No delay. If fn is locked by another process, setlock gives up.
-N
(Default.) Delay. If fn is locked by another process, setlock waits until it can obtain a new lock.
-x
If fn cannot be update-item (or put-item) or locked, setlock exits zero.
-X
(Default.) If fn cannot be update-item (or put-item) or locked, setlock prints an error message and exits nonzero.
--debug
show debug log
--endpoint string
If you switch remote, set AWS DynamoDB endpoint url.
--region string
aws region
--timeout string
set command timeout
--version
show version
```the required IAM Policy is as follows:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"dynamodb:CreateTable",
"dynamodb:UpdateTimeToLive",
"dynamodb:PutItem",
"dynamodb:DescribeTable",
"dynamodb:GetItem",
"dynamodb:UpdateItem"
],
"Resource": "*"
}
]
}
```If the lock table has already been created, `dynamodb:CreateTable` and `dynamodb:UpdateTimeToLive` are not required.
## Install### binary packages
[Releases](https://github.com/mashiike/setddblock/releases).
### Homebrew tap
```console
$ brew install mashiike/tap/setddblock
```## Usage as a library
`setddblock.New(url string, optFns ...func(*setddblock.Options))` returns a DynamoDBLocker that satisfies the sync.Locker interface.
```go
l, err := setddblock.New("ddb://ddb_lock_table/lock_item_id")
if err != nil {
// ...
}
func () {
l.Lock()
defer l.Unlock()
// ...
}()
```Note: If Lock or Unlock fails, for example because you can't connect to DynamoDB, it will panic.
If you don't want it to panic, use `LockWithError()` and `UnlockWithErr()`. Alternatively, use the `WithNoPanic` option.more infomation see [go doc](https://godoc.org/github.com/mashiike/setddblock).
## Licensesee [LICENSE](https://github.com/mashiike/setddblock/blob/master/LICENSE) file.