How can I convert a DynamoDB view JSON to a normal JSON? #682
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.
-
For example, I want to convert:
to this:
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
unmarshall
for JavaScript orTypeDeserializer.deserialize
for Python?Beta Was this translation helpful? Give feedback.
All reactions