Skip to content

[DynamoDB event] Makes ApproximateCreationDateTime optional in StreamRecord #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lambda-events/src/event/dynamodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Utc>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not want to change contracts by making this Option<DateTime<Utc>>, but if that makes more sense please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good approach, thanks!

/// The primary key attribute(s) for the DynamoDB item that was modified.
#[serde(deserialize_with = "deserialize_lambda_dynamodb_item")]
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"recordFormat":"application/json",
"tableName":"examples",
"dynamodb":{
"ApproximateCreationDateTime":1649809356015,
"Keys":{
"id":{
"S":"00000000-0000-0000-0000-000000000000"
Expand Down
Loading