diff --git a/aws_lambda_events/src/dynamodb/mod.rs b/aws_lambda_events/src/dynamodb/mod.rs index 01a96f7..774de4a 100644 --- a/aws_lambda_events/src/dynamodb/mod.rs +++ b/aws_lambda_events/src/dynamodb/mod.rs @@ -137,6 +137,8 @@ pub struct EventRecord { pub event_name: String, /// The AWS service from which the stream record originated. For DynamoDB Streams, /// this is aws:dynamodb. + #[serde(deserialize_with = "deserialize_lambda_string")] + #[serde(default)] pub event_source: Option, /// The version number of the stream record format. This number is updated whenever /// the structure of Record is modified. @@ -144,9 +146,13 @@ pub struct EventRecord { /// Client applications must not assume that eventVersion will remain at a particular /// value, as this number is subject to change at any time. In general, eventVersion /// will only increase as the low-level DynamoDB Streams API evolves. + #[serde(deserialize_with = "deserialize_lambda_string")] + #[serde(default)] pub event_version: Option, /// The event source ARN of DynamoDB #[serde(rename = "eventSourceARN")] + #[serde(deserialize_with = "deserialize_lambda_string")] + #[serde(default)] pub event_source_arn: Option, /// Items that are deleted by the Time to Live process after expiration have /// the following fields: @@ -158,12 +164,17 @@ pub struct EventRecord { /// * Records[].userIdentity.principalId /// /// "dynamodb.amazonaws.com" + #[serde(default)] pub user_identity: Option, /// Describes the record format and relevant mapping information that /// should be applied to schematize the records on the stream. For /// DynamoDB Streams, this is application/json. + #[serde(deserialize_with = "deserialize_lambda_string")] + #[serde(default)] pub record_format: Option, /// The DynamoDB table that this event was recorded for. + #[serde(deserialize_with = "deserialize_lambda_string")] + #[serde(default)] pub table_name: Option, } @@ -236,4 +247,16 @@ mod test { let date = Utc.ymd(2016, 12, 2).and_hms(1, 27, 0); assert_eq!(date, event.change.approximate_creation_date_time); } + + #[test] + #[cfg(feature = "dynamodb")] + fn example_dynamodb_event_with_optional_fields() { + let data = include_bytes!( + "../generated/fixtures/example-dynamodb-event-record-with-optional-fields.json" + ); + let parsed: EventRecord = serde_json::from_slice(data).unwrap(); + let output: String = serde_json::to_string(&parsed).unwrap(); + let reparsed: EventRecord = serde_json::from_slice(output.as_bytes()).unwrap(); + assert_eq!(parsed, reparsed); + } } diff --git a/aws_lambda_events/src/generated/fixtures/example-dynamodb-event-record-with-optional-fields.json b/aws_lambda_events/src/generated/fixtures/example-dynamodb-event-record-with-optional-fields.json new file mode 100644 index 0000000..873cccc --- /dev/null +++ b/aws_lambda_events/src/generated/fixtures/example-dynamodb-event-record-with-optional-fields.json @@ -0,0 +1,26 @@ +{ + "awsRegion":"eu-west-1", + "eventID":"00000000-0000-0000-0000-000000000000", + "eventName":"INSERT", + "userIdentity":null, + "recordFormat":"application/json", + "tableName":"examples", + "dynamodb":{ + "ApproximateCreationDateTime":1649809356015, + "Keys":{ + "id":{ + "S":"00000000-0000-0000-0000-000000000000" + } + }, + "NewImage":{ + "id":{ + "S":"00000000-0000-0000-0000-000000000000" + }, + "created":{ + "S":"2022-02-16T15:12:00.14Z" + } + }, + "SizeBytes":292 + }, + "eventSource":"aws:dynamodb" +}