From d03bbc4caafc3f58abe84bd0c941c3f65b91f68b Mon Sep 17 00:00:00 2001 From: stelo <42366677+jfkisafk@users.noreply.github.com> Date: Thu, 6 Jun 2024 08:07:34 -0700 Subject: [PATCH] fix(events): makes ApproximateCreationDateTime optional in dynamo event stream record (#891) closes https://github.com/awslabs/aws-lambda-rust-runtime/issues/889 --- lambda-events/src/event/dynamodb/mod.rs | 6 +++++- .../example-dynamodb-event-record-with-optional-fields.json | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lambda-events/src/event/dynamodb/mod.rs b/lambda-events/src/event/dynamodb/mod.rs index 33b977bd..77cc77d2 100644 --- a/lambda-events/src/event/dynamodb/mod.rs +++ b/lambda-events/src/event/dynamodb/mod.rs @@ -213,9 +213,11 @@ pub struct UserIdentity { #[serde(rename_all = "camelCase")] pub struct StreamRecord { /// The approximate date and time when the stream record was created, in UNIX - /// epoch time (http://www.epochconverter.com/) format. + /// epoch time (http://www.epochconverter.com/) format. Might not be present in + /// the record: https://github.com/awslabs/aws-lambda-rust-runtime/issues/889 #[serde(rename = "ApproximateCreationDateTime")] #[serde(with = "float_unix_epoch")] + #[serde(default)] pub approximate_creation_date_time: DateTime, /// The primary key attribute(s) for the DynamoDB item that was modified. #[serde(deserialize_with = "deserialize_lambda_dynamodb_item")] @@ -274,5 +276,7 @@ mod test { let output: String = serde_json::to_string(&parsed).unwrap(); let reparsed: EventRecord = serde_json::from_slice(output.as_bytes()).unwrap(); assert_eq!(parsed, reparsed); + let date = Utc.timestamp_micros(0).unwrap(); // 1970-01-01T00:00:00Z + assert_eq!(date, reparsed.change.approximate_creation_date_time); } } diff --git a/lambda-events/src/fixtures/example-dynamodb-event-record-with-optional-fields.json b/lambda-events/src/fixtures/example-dynamodb-event-record-with-optional-fields.json index 873cccce..4f468c70 100644 --- a/lambda-events/src/fixtures/example-dynamodb-event-record-with-optional-fields.json +++ b/lambda-events/src/fixtures/example-dynamodb-event-record-with-optional-fields.json @@ -6,7 +6,6 @@ "recordFormat":"application/json", "tableName":"examples", "dynamodb":{ - "ApproximateCreationDateTime":1649809356015, "Keys":{ "id":{ "S":"00000000-0000-0000-0000-000000000000"