aws_utils_dynamodb
AWS DynamoDB utilities for Rust, providing a simplified interface for common DynamoDB operations.
Features
- Simple DynamoDB client creation with configurable endpoint
- Record operations (CRUD)
- Table management operations
- Stream-based pagination for scan and query operations
- CSV import functionality from S3
- Error handling with custom error types
Installation
Add this to your Cargo.toml
:
[]
= { = "crates/dynamodb" }
Usage
Creating a Client
use make_client;
// Create client with default AWS configuration
let client = make_client.await;
// Create client with custom endpoint (e.g., for local DynamoDB)
let client = make_client.await;
Record Operations
use ;
use ;
use HashMap;
// Get an item
let mut key = new;
key.insert;
let item = get_item.await?;
// Put an item
let mut item = new;
item.insert;
item.insert;
let output = put_item.await?;
// Update an item
let mut key = new;
key.insert;
let output = update_item.await?;
// Delete an item
let mut key = new;
key.insert;
let output = delete_item.await?;
// Scan all items
let items = scan_all.await?;
// Query items
let items = query_all.await?;
Table Operations
use ;
use ;
// Create a table with on-demand billing
let attrs = vec!;
let output = create_table.await?;
// Create a table with provisioned capacity
let output = create_table.await?;
// Delete a table
let output = delete_table.await?;
// Get table capacity
let = get_capacity.await?;
// Update table capacity
let output = set_capacity.await?;
CSV Import from S3
use import_table;
use TableType;
use ;
// Import CSV data from S3 to a new DynamoDB table
let attrs = vec!;
import_table.await?;
Stream Operations
For handling large datasets, use stream-based operations:
use ;
use TryStreamExt;
// Scan with streaming
let stream = scan_stream;
pin_mut!;
while let Some = stream.try_next.await?
// Query with streaming
let stream = query_stream;
pin_mut!;
while let Some = stream.try_next.await?
Error Handling
The crate provides a custom Error
type that wraps AWS SDK errors and includes common error cases:
NotFound
- Item not foundValidationError
- Invalid parameters or stateInvalid
- Invalid response from AWSAwsSdkError
- AWS SDK specific errors
Environment Variables
The client creation automatically sets default values for AWS credentials if not present:
AWS_ACCESS_KEY_ID
- Defaults to "dummy_access_key"AWS_SECRET_ACCESS_KEY
- Defaults to "dummy_secret_key"AWS_REGION
- Defaults to "us-west-2"
These defaults are useful for local development with DynamoDB Local.
License
This project is part of the utilities.aws-utils workspace.