Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Test dynamodb optional fields. #86

Merged
merged 1 commit into from
Apr 29, 2022
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
23 changes: 23 additions & 0 deletions aws_lambda_events/src/dynamodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,22 @@ 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<String>,
/// The version number of the stream record format. This number is updated whenever
/// the structure of Record is modified.
///
/// 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<String>,
/// The event source ARN of DynamoDB
#[serde(rename = "eventSourceARN")]
#[serde(deserialize_with = "deserialize_lambda_string")]
#[serde(default)]
pub event_source_arn: Option<String>,
/// Items that are deleted by the Time to Live process after expiration have
/// the following fields:
Expand All @@ -158,12 +164,17 @@ pub struct EventRecord {
/// * Records[].userIdentity.principalId
///
/// "dynamodb.amazonaws.com"
#[serde(default)]
pub user_identity: Option<UserIdentity>,
/// 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<String>,
/// The DynamoDB table that this event was recorded for.
#[serde(deserialize_with = "deserialize_lambda_string")]
#[serde(default)]
pub table_name: Option<String>,
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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"
}