diff --git a/examples/http-dynamodb/Cargo.toml b/examples/http-dynamodb/Cargo.toml index c3f6d8be..be95f867 100644 --- a/examples/http-dynamodb/Cargo.toml +++ b/examples/http-dynamodb/Cargo.toml @@ -11,15 +11,16 @@ edition = "2021" # and it will keep the alphabetic ordering for you. [dependencies] -simple-error = "0.2.3" -serde_json = "1.0" -serde = { version = "1.0", features = ["derive"] } +simple-error = "0.3.0" +serde_json = "1.0.107" +serde = { version = "1.0.189", features = ["derive"] } +serde_dynamo = {version = "^4.2.7", features = ["aws-sdk-dynamodb+0_33"]} lambda_http = { path = "../../lambda-http" } lambda_runtime = { path = "../../lambda-runtime" } -aws-sdk-dynamodb = "0.21.0" -aws-config = "0.51.0" -tokio = { version = "1", features = ["macros"] } -tracing = { version = "0.1", features = ["log"] } -tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] } +aws-sdk-dynamodb = "0.33.0" +aws-config = "0.56.1" +tokio = { version = "1.33.0", features = ["macros"] } +tracing = { version = "0.1.40", features = ["log"] } +tracing-subscriber = { version = "0.3.17", default-features = false, features = ["fmt"] } diff --git a/examples/http-dynamodb/src/main.rs b/examples/http-dynamodb/src/main.rs index 5a7030f9..b2e8af20 100644 --- a/examples/http-dynamodb/src/main.rs +++ b/examples/http-dynamodb/src/main.rs @@ -1,9 +1,10 @@ -use aws_sdk_dynamodb::model::AttributeValue; -use aws_sdk_dynamodb::{Client, Error as OtherError}; +use aws_sdk_dynamodb::{Client}; use lambda_http::{run, service_fn, Body, Error, Request, Response}; +use serde::{Deserialize, Serialize}; +use serde_dynamo::to_attribute_value; use tracing::info; -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct Item { pub p_type: String, pub age: String, @@ -76,12 +77,12 @@ async fn main() -> Result<(), Error> { // Add an item to a table. // snippet-start:[dynamodb.rust.add-item] -pub async fn add_item(client: &Client, item: Item, table: &str) -> Result<(), OtherError> { - let user_av = AttributeValue::S(item.username); - let type_av = AttributeValue::S(item.p_type); - let age_av = AttributeValue::S(item.age); - let first_av = AttributeValue::S(item.first); - let last_av = AttributeValue::S(item.last); +pub async fn add_item(client: &Client, item: Item, table: &str) -> Result<(), Error> { + let user_av = to_attribute_value(item.username)?; + let type_av = to_attribute_value(item.p_type)?; + let age_av = to_attribute_value(item.age)?; + let first_av = to_attribute_value(item.first)?; + let last_av = to_attribute_value(item.last)?; let request = client .put_item()