-
Notifications
You must be signed in to change notification settings - Fork 54
Use serde_dynamo
for dynamodb::Event
items
#140
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some additional tests?
Absolutely! What sorts of tests would you like to see? Parsing from DynamoDB's JSON format to Or are there other aspects that would help increase confidence that this will work? |
I just added the existing |
@@ -139,6 +139,18 @@ where | |||
Ok(opt.unwrap_or_default()) | |||
} | |||
|
|||
/// Deserializes `Item`, mapping JSON `null` to an empty item. | |||
pub(crate) fn deserialize_lambda_dynamodb_item<'de, D>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code needs to be behind a feature flag. Otherwise, the library will fail to compile when dynamodb
is not enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check the serialization module?
Use `serde_dynamo::Item` instead of `HashMap<String, AttributeValue>` to represent the `keys`, `old_image`, and `new_image` in a `dynamodb::Event`. This consolidates the Rust/DynamoDB ecosystem around fewer representations of DynamoDB items. Note that `serde_dynamo::AttributeValue` and `aws_lambda_events::dynamodb::attributes::AttributeValue` are slightly different (especially with regards to the `Number` enumeration) so this is a breaking change that would either need to go behind a feature flag or a major version bump.
Changes in this most recent commit:
|
Use `serde_dynamo::Item` instead of `HashMap<String, AttributeValue>` to represent the `keys`, `old_image`, and `new_image` in a `dynamodb::Event`. This consolidates the Rust/DynamoDB ecosystem around fewer representations of DynamoDB items. Note that `serde_dynamo::AttributeValue` and `aws_lambda_events::dynamodb::attributes::AttributeValue` are slightly different (especially with regards to the `Number` enumeration) so this is a breaking change that would either need to go behind a feature flag or a major version bump. (cherry picked from commit 50ce8ed) Signed-off-by: David Calavera <david.calavera@gmail.com>
Use `serde_dynamo::Item` instead of `HashMap<String, AttributeValue>` to represent the `keys`, `old_image`, and `new_image` in a `dynamodb::Event`. This consolidates the Rust/DynamoDB ecosystem around fewer representations of DynamoDB items. Note that `serde_dynamo::AttributeValue` and `aws_lambda_events::dynamodb::attributes::AttributeValue` are slightly different (especially with regards to the `Number` enumeration) so this is a breaking change that would either need to go behind a feature flag or a major version bump. (cherry picked from commit 50ce8ed) Signed-off-by: David Calavera <david.calavera@gmail.com> Co-authored-by: Bryan Burgers <bryan@burgers.io>
@@ -169,7 +29,7 @@ mod test { | |||
|
|||
let attr: AttributeValue = serde_json::from_value(value.clone()).unwrap(); | |||
match attr { | |||
AttributeValue::String(ref s) => assert_eq!("value", s.as_str()), | |||
AttributeValue::S(ref s) => assert_eq!("value", s.as_str()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my humble opinion this is a regression in readability. Fully spelled out variant names with the appropriate #[serde(rename = "…")]
attributes seemed better.
Use
serde_dynamo::Item
instead ofHashMap<String, AttributeValue>
to represent thekeys
,old_image
, andnew_image
in adynamodb::Event
.This consolidates the Rust/DynamoDB ecosystem around fewer representations of DynamoDB items.
Note that
serde_dynamo::AttributeValue
andaws_lambda_events::dynamodb::attributes::AttributeValue
are slightly different (especially with regards to theNumber
enumeration) so this is a breaking change that would either need to go behind a feature flag or a major version bump.I feel like this might be of interest to the wider community because
dynamodb::Event
andserde_dynamo
used together already, andserde_json
, this helps prompt users to convert to a typed representation of their entity earlier.I'm curious whether you think this is useful for aws-lambda-events and the wider Rust+AWS ecosystem.