Skip to content

Commit d03bbc4

Browse files
authored
fix(events): makes ApproximateCreationDateTime optional in dynamo event stream record (#891)
closes #889
1 parent 1cf868c commit d03bbc4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lambda-events/src/event/dynamodb/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,11 @@ pub struct UserIdentity {
213213
#[serde(rename_all = "camelCase")]
214214
pub struct StreamRecord {
215215
/// The approximate date and time when the stream record was created, in UNIX
216-
/// epoch time (http://www.epochconverter.com/) format.
216+
/// epoch time (http://www.epochconverter.com/) format. Might not be present in
217+
/// the record: https://github.com/awslabs/aws-lambda-rust-runtime/issues/889
217218
#[serde(rename = "ApproximateCreationDateTime")]
218219
#[serde(with = "float_unix_epoch")]
220+
#[serde(default)]
219221
pub approximate_creation_date_time: DateTime<Utc>,
220222
/// The primary key attribute(s) for the DynamoDB item that was modified.
221223
#[serde(deserialize_with = "deserialize_lambda_dynamodb_item")]
@@ -274,5 +276,7 @@ mod test {
274276
let output: String = serde_json::to_string(&parsed).unwrap();
275277
let reparsed: EventRecord = serde_json::from_slice(output.as_bytes()).unwrap();
276278
assert_eq!(parsed, reparsed);
279+
let date = Utc.timestamp_micros(0).unwrap(); // 1970-01-01T00:00:00Z
280+
assert_eq!(date, reparsed.change.approximate_creation_date_time);
277281
}
278282
}

lambda-events/src/fixtures/example-dynamodb-event-record-with-optional-fields.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"recordFormat":"application/json",
77
"tableName":"examples",
88
"dynamodb":{
9-
"ApproximateCreationDateTime":1649809356015,
109
"Keys":{
1110
"id":{
1211
"S":"00000000-0000-0000-0000-000000000000"

0 commit comments

Comments
 (0)