aws-sdk-rust
aws-sdk-rust copied to clipboard
[request]: A crate similar to serde_dynamo
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue, please leave a comment
Tell us about your request serde_dynamo provides a way to serialize and deserialize between data stored in these Items and strongly-typed Rust data structures. Would be nice to have something similar for aws-sdk-rust.
Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?
Currently my team is switching from using rusoto to aws-sdk-rust. One part of our code is to deserialize the items from DynamoDb with serde_dynamo::from_items but can no long us this because from_items uses rusoto AttributeValue. I searched for something similar in aws sdk rust docs but couldn't find anything.
Are you currently working around this issue? I would need to recreate what serde_dynamo::from_items does.
Additional context N/A
Attachments N/A
Thanks for submitting this. We have a few different serialization/deserialization requests we're looking at right now.
It looks like the maintainers of serde_dynamo are looking at what it would take to support the new SDK and they have a merged PR that seems like it might implement it behind a feature flag. That'd probably be your best short term bet.
seems like there's an open issue presently: https://github.com/zenlist/serde_dynamo/pull/14
FWIW, I just released 3.0.0-alpha.1 of serde_dynamo, if you want to give it a try and provide feedback.
[package]
name = "aws_sdk_example"
version = "0.1.0"
edition = "2021"
[dependencies]
aws-config = { version = "0.0.25-alpha" }
aws-sdk-dynamodb = { version = "0.0.25-alpha" }
serde = { version = "1", features = ["derive"] }
serde_dynamo = { version = "3.0.0-alpha.1", features = ["aws-sdk-dynamodb+0_0_25-alpha"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
use aws_config::meta::region::RegionProviderChain;
use aws_sdk_dynamodb::{Client, Region};
use serde::{Deserialize, Serialize};
use serde_dynamo::from_items;
type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
#[derive(Debug, Serialize, Deserialize)]
struct User {
id: UserId,
first_name: String,
last_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(transparent)]
struct UserId(String);
#[tokio::main]
async fn main() -> Result<()> {
let region_provider = RegionProviderChain::default_provider().or_else(Region::new("us-west-2"));
let shared_config = aws_config::from_env().region(region_provider).load().await;
let client = Client::new(&shared_config);
let resp = client
.scan()
.table_name("users")
.projection_expression("id, first_name, last_name")
.send()
.await?;
if let Some(items) = resp.items {
let items: Vec<User> = from_items(items)?;
println!("{:#?}", items);
}
Ok(())
}
Thanks for sharing this @bryanburgers. This is a great example.
so now that serde_dynamo is compatible with the official AWS SDK, we can close this issue or the AWS SDK will ship its own serde implementation?