pub fn to_attribute_value<T, AV>(value: T) -> Result<AV>
where T: Serialize, AV: From<AttributeValue>,
Expand description

Convert a T into an AttributeValue.

In some circumstances, building aws_sdk_dynamodb::model::AttributeValues directly is required.

For example, when generating a key to supply to get_item.

use serde_dynamo::to_attribute_value;

// Create the unique key of the record in DynamoDB in a way rusoto understands
let key = HashMap::from([
    (String::from("id"), to_attribute_value(&,

// And get the record

Or when generating attribute values in a query call.

use serde_dynamo::to_attribute_value;

// Declare all of the expression inputs for a query call
let expression_attribute_values = HashMap::from([
    (String::from(":user_type"), to_attribute_value(user_type)?),
    (String::from(":last_login"), to_attribute_value(yesterday)?),

    .key_condition_expression("user_type = :user_type AND last_login > :last_login")