How can I convert a DynamoDB view JSON to a normal JSON? #682
-
For example, I want to convert: {
"id": {
"N": "123"
},
"name": {
"S": "some name"
}
} to this: {
"id": 123,
"name": "some name"
} I've found this question https://stackoverflow.com/questions/32712675/formatting-dynamodb-data-to-normal-json-in-aws-lambda with several answers for Node.js or Python. Is there a converter like |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
Use this: serde_dynamo Edit: Changed the crate name to the correct one. |
Beta Was this translation helpful? Give feedback.
-
This does not work for me using a dynamDB like this: use lambda_runtime::{service_fn, Error, LambdaEvent};
use serde_json::Value;
async fn func(event: LambdaEvent<Value>) -> Result<(), Error> {
let config = aws_config::load_from_env().await;
let dynamodb = aws_sdk_dynamodb::Client::new(&config);
let response = dynamodb.scan().table_name("Temperatures").send().await?;
let items = response.items().unwrap();
let item = items[0];
let res = serde_dynamodb::from_hashmap(item);
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let func = service_fn(func);
lambda_runtime::run(func).await?;
Ok(())
} There is a type mismatch for AttributeValue:
I don't want to use |
Beta Was this translation helpful? Give feedback.
-
Sorry I ment serde_dynamo. Also see #521 |
Beta Was this translation helpful? Give feedback.
-
Quite the same problem here. AttributeValues are defined in I'm trying this: use lambda_runtime::{service_fn, Error, LambdaEvent};
use serde_json::Value;
async fn func(event: LambdaEvent<Value>) -> Result<(), Error> {
let config = aws_config::load_from_env().await;
let dynamodb = aws_sdk_dynamodb::Client::new(&config);
let response = dynamodb.scan().table_name("Temperatures").send().await?;
let items = response.items().unwrap();
let res = serde_dynamo::from_items(items.to_owned()).unwrap();
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let func = service_fn(func);
lambda_runtime::run(func).await?;
Ok(())
} and get the following compile error:
|
Beta Was this translation helpful? Give feedback.
-
Does not work. I've asked in the serde_dynamo repo. |
Beta Was this translation helpful? Give feedback.
-
You need manually convert each type to your struct. Imagine this model
When you query:
|
Beta Was this translation helpful? Give feedback.
It would be great to add these, it's just not a priority for us right now. We are working very hard to get our ducks in a row for a 1.0 release right now, and it's going to be a little while before we can focus on quality-of-life improvements like this.
That being said, we welcome PRs from outside contributors. If you can design, implement, test, and PR this feature, we'll review your PR as soon as we're able.