Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryeguard/ddbcalc
A DynamoDB item size calculator.
https://github.com/ryeguard/ddbcalc
aws aws-dynamo aws-dynamodb aws-sdk aws-sdk-go aws-sdk-go-v2 dynamo dynamodb
Last synced: about 2 months ago
JSON representation
A DynamoDB item size calculator.
- Host: GitHub
- URL: https://github.com/ryeguard/ddbcalc
- Owner: ryeguard
- License: other
- Created: 2024-02-24T10:37:16.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-11-17T01:42:18.000Z (about 2 months ago)
- Last Synced: 2024-11-17T02:29:33.060Z (about 2 months ago)
- Topics: aws, aws-dynamo, aws-dynamodb, aws-sdk, aws-sdk-go, aws-sdk-go-v2, dynamo, dynamodb
- Language: Go
- Homepage:
- Size: 128 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ddbcalc
[![Go Reference](https://pkg.go.dev/badge/github.com/ryeguard/ddbcalc.svg)](https://pkg.go.dev/github.com/ryeguard/ddbcalc)
[![Go Report Card](https://goreportcard.com/badge/github.com/ryeguard/ddbcalc)](https://goreportcard.com/report/github.com/ryeguard/ddbcalc)
[![Go Coverage](https://github.com/ryeguard/ddbcalc/wiki/coverage.svg)](https://raw.githack.com/wiki/ryeguard/ddbcalc/coverage.html)A DynamoDB item size calculator.
This package has no dependencies other than AWS's [aws-sdk-go-v2](https://github.com/aws/aws-sdk-go-v2).
## Raison d'être
DynamoDB has a limit of 400KB for the size of an item. The `ddbcalc` package provides functionality to calculate the size of any Go struct in bytes. This can be useful when you need to ensure that the size of an item does not exceed the limit, either through tests or at runtime.
For more info, please see the blog post at [rygard.se](https://www.rygard.se/blog/240220_dynamodb_item_size/240220_dynamodb_item_size.html).
## Usage
### CLI
The `ddbcalc` command-line tool can be used to calculate the size of a json file from the terminal.
Install the tool with the following command:
```sh
go install github.com/ryeguard/ddbcalc/cmd/ddbcalc@latest
```You can then run the tool with the following command:
```sh
ddbcalc -file path/to/file.json
```### Package
By importing `github.com/ryeguard/ddbcalc`, you can use the modules's exported functions in your Go code.
For example, the `StructSizeInBytes` function calculates the size of a struct in bytes. It may be used as follows:
```go
package mainimport (
"fmt""github.com/ryeguard/ddbcalc"
)type Item struct {
ID string
Name string
Age int
Email string
}func main() {
item := Item{
ID: "123",
Name: "John Doe",
Age: 30,
Email: "[email protected]",
}size, err := ddbcalc.StructSizeInBytes(item)
if err != nil {
fmt.Println(err)
return
}fmt.Printf("Item size: %d bytes\n", size)
}
```You can run the example above with the following command:
```sh
go run example/basic/main.go
```For more examples, see the [examples](./examples) directory and also check out the tests in any [`*_test.go`](https://github.com/search?q=repo%3Aryeguard%2Fddbcalc+path%3A*_test.go&type=code) files.
## Contributing
Contributions are welcome in any shape or form. Please feel free to open an issue or a pull request.
## License
This project is licensed under the MIT License. However, it includes dependencies licensed under the Apache License 2.0. See the LICENSE and NOTICE files for details.