Crates.io | dynamodb-tools |
lib.rs | dynamodb-tools |
version | 0.4.0 |
source | src |
created_at | 2022-12-12 01:06:21.002216 |
updated_at | 2023-12-24 07:05:32.273892 |
description | A simple library to work with dynamodb local easy. |
homepage | https://github.com/tyrchen/dynamodb-tools |
repository | https://github.com/tyrchen/dynamodb-tools |
max_upload_size | |
id | 734581 |
size | 38,295 |
This crate is previously called dynamodb-tester, but I decided to rename it to dynamodb-tools, because it is not only for testing.
As AWS provided DynamoDB local, we could leverage it in the development & test environment. However, managing the dynamodb client and tables is tedious, we need to clean that up at the end of every test to not pollute other tests. This crate will help you to create tables with unique names and then tear them down after test ends (by using Drop trait if you ask).
First you need to download and run dynamodb local yourself. For example, I unzipped it in ~/bin/dynamodb_local_latest, so I can start it like this:
$ java -Djava.library.path=~/bin/dynamodb_local_latest/DynamoDBLocal_lib -jar ~/bin/dynamodb_local_latest/DynamoDBLocal.jar -inMemory -sharedDb
Feel free to make it a service so that it starts automatically when system starts.
In your test code, you could use it like this:
// first, create the LocalClient
use dynamodb_tools::DynamodbConnector;
let connector = DynamodbConnector::try_new("fixtures/config.yml").await?;
// then you could use the returned client & table_name
// to interact with dynamodb local.
let ret = connector.client
.put_item()
.table_name(connector.table_name().unwrap())
.set_item(Some(item))
.send()
.await?;
If you want to integrate it with github action, you could use this action:
- name: Setup DynamoDB Local
uses: rrainn/dynamodb-action@v2.0.1
with:
port: 8000
cors: '*'
See build.yml for more details.