This repository has been archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catchup with current version of aws-lambda-go (#28)
- Loading branch information
1 parent
c802ff7
commit 168959e
Showing
7 changed files
with
261 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
aws_lambda_events/src/generated/fixtures/example-kafka-event.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"eventSource": "aws:kafka", | ||
"eventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/ExampleMSKCluster/e9f754c6-d29a-4430-a7db-958a19fd2c54-4", | ||
"records": { | ||
"AWSKafkaTopic-0": [ | ||
{ | ||
"topic": "AWSKafkaTopic", | ||
"partition": 0, | ||
"offset": 0, | ||
"timestamp": 1595035749700, | ||
"timestampType": "CREATE_TIME", | ||
"key": "OGQ1NTk2YjQtMTgxMy00MjM4LWIyNGItNmRhZDhlM2QxYzBj", | ||
"value": "OGQ1NTk2YjQtMTgxMy00MjM4LWIyNGItNmRhZDhlM2QxYzBj" | ||
} | ||
] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use super::super::encodings::MillisecondTimestamp; | ||
use crate::custom_serde::*; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] | ||
pub struct KafkaEvent { | ||
#[serde(deserialize_with = "deserialize_lambda_string")] | ||
#[serde(default)] | ||
#[serde(rename = "eventSource")] | ||
pub event_source: Option<String>, | ||
#[serde(deserialize_with = "deserialize_lambda_string")] | ||
#[serde(default)] | ||
#[serde(rename = "eventSourceArn")] | ||
pub event_source_arn: Option<String>, | ||
#[serde(deserialize_with = "deserialize_lambda_map")] | ||
#[serde(default)] | ||
pub records: HashMap<String, Vec<KafkaRecord>>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] | ||
pub struct KafkaRecord { | ||
#[serde(deserialize_with = "deserialize_lambda_string")] | ||
#[serde(default)] | ||
pub topic: Option<String>, | ||
pub partition: i64, | ||
pub offset: i64, | ||
pub timestamp: MillisecondTimestamp, | ||
#[serde(deserialize_with = "deserialize_lambda_string")] | ||
#[serde(default)] | ||
#[serde(rename = "timestampType")] | ||
pub timestamp_type: Option<String>, | ||
pub key: Option<String>, | ||
pub value: Option<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
extern crate serde_json; | ||
|
||
#[test] | ||
fn example_event() { | ||
let data = include_bytes!("fixtures/example-kafka-event.json"); | ||
let parsed: KafkaEvent = serde_json::from_slice(data).unwrap(); | ||
let output: String = serde_json::to_string(&parsed).unwrap(); | ||
let reparsed: KafkaEvent = serde_json::from_slice(output.as_bytes()).unwrap(); | ||
assert_eq!(parsed, reparsed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters