Skip to main content

aws_lambda_events/event/firehose/
mod.rs

1use crate::{
2    custom_serde::deserialize_nullish,
3    encodings::{Base64Data, MillisecondTimestamp},
4};
5#[cfg(feature = "builders")]
6use bon::Builder;
7use serde::{Deserialize, Serialize};
8#[cfg(feature = "catch-all-fields")]
9use serde_json::Value;
10use std::collections::HashMap;
11
12/// `KinesisFirehoseEvent` represents the input event from Amazon Kinesis Firehose. It is used as the input parameter.
13#[non_exhaustive]
14#[cfg_attr(feature = "builders", derive(Builder))]
15#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
16#[serde(rename_all = "camelCase")]
17pub struct KinesisFirehoseEvent {
18    #[serde(default)]
19    pub invocation_id: Option<String>,
20    /// nolint: stylecheck
21    #[serde(default)]
22    pub delivery_stream_arn: Option<String>,
23    /// nolint: stylecheck
24    #[serde(default)]
25    pub source_kinesis_stream_arn: Option<String>,
26    #[serde(default)]
27    pub region: Option<String>,
28    pub records: Vec<KinesisFirehoseEventRecord>,
29    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
30    /// Enabled with Cargo feature `catch-all-fields`.
31    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
32    #[cfg(feature = "catch-all-fields")]
33    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
34    #[serde(flatten)]
35    #[cfg_attr(feature = "builders", builder(default))]
36    pub other: serde_json::Map<String, Value>,
37}
38
39#[non_exhaustive]
40#[cfg_attr(feature = "builders", derive(Builder))]
41#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
42#[serde(rename_all = "camelCase")]
43pub struct KinesisFirehoseEventRecord {
44    #[serde(default)]
45    pub record_id: Option<String>,
46    pub approximate_arrival_timestamp: MillisecondTimestamp,
47    pub data: Base64Data,
48    #[serde(rename = "kinesisRecordMetadata")]
49    pub kinesis_firehose_record_metadata: Option<KinesisFirehoseRecordMetadata>,
50    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
51    /// Enabled with Cargo feature `catch-all-fields`.
52    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
53    #[cfg(feature = "catch-all-fields")]
54    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
55    #[serde(flatten)]
56    #[cfg_attr(feature = "builders", builder(default))]
57    pub other: serde_json::Map<String, Value>,
58}
59
60#[non_exhaustive]
61#[cfg_attr(feature = "builders", derive(Builder))]
62#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
63#[serde(rename_all = "camelCase")]
64pub struct KinesisFirehoseResponse {
65    pub records: Vec<KinesisFirehoseResponseRecord>,
66    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
67    /// Enabled with Cargo feature `catch-all-fields`.
68    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
69    #[cfg(feature = "catch-all-fields")]
70    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
71    #[serde(flatten)]
72    #[cfg_attr(feature = "builders", builder(default))]
73    pub other: serde_json::Map<String, Value>,
74}
75
76#[non_exhaustive]
77#[cfg_attr(feature = "builders", derive(Builder))]
78#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
79#[serde(rename_all = "camelCase")]
80pub struct KinesisFirehoseResponseRecord {
81    #[serde(default)]
82    pub record_id: Option<String>,
83    /// The status of the transformation. May be TransformedStateOk, TransformedStateDropped or TransformedStateProcessingFailed
84    #[serde(default)]
85    pub result: Option<String>,
86    pub data: Base64Data,
87    pub metadata: KinesisFirehoseResponseRecordMetadata,
88    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
89    /// Enabled with Cargo feature `catch-all-fields`.
90    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
91    #[cfg(feature = "catch-all-fields")]
92    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
93    #[serde(flatten)]
94    #[cfg_attr(feature = "builders", builder(default))]
95    pub other: serde_json::Map<String, Value>,
96}
97
98#[non_exhaustive]
99#[cfg_attr(feature = "builders", derive(Builder))]
100#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
101#[serde(rename_all = "camelCase")]
102pub struct KinesisFirehoseResponseRecordMetadata {
103    #[serde(deserialize_with = "deserialize_nullish")]
104    #[serde(default)]
105    pub partition_keys: HashMap<String, String>,
106    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
107    /// Enabled with Cargo feature `catch-all-fields`.
108    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
109    #[cfg(feature = "catch-all-fields")]
110    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
111    #[serde(flatten)]
112    #[cfg_attr(feature = "builders", builder(default))]
113    pub other: serde_json::Map<String, Value>,
114}
115
116#[non_exhaustive]
117#[cfg_attr(feature = "builders", derive(Builder))]
118#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
119#[serde(rename_all = "camelCase")]
120pub struct KinesisFirehoseRecordMetadata {
121    #[serde(default)]
122    pub shard_id: Option<String>,
123    #[serde(default)]
124    pub partition_key: Option<String>,
125    #[serde(default)]
126    pub sequence_number: Option<String>,
127    pub subsequence_number: i64,
128    pub approximate_arrival_timestamp: MillisecondTimestamp,
129    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
130    /// Enabled with Cargo feature `catch-all-fields`.
131    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
132    #[cfg(feature = "catch-all-fields")]
133    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
134    #[serde(flatten)]
135    #[cfg_attr(feature = "builders", builder(default))]
136    pub other: serde_json::Map<String, Value>,
137}
138
139#[cfg(test)]
140mod test {
141    use super::*;
142
143    #[test]
144    #[cfg(feature = "firehose")]
145    fn example_firehose_event() {
146        let data = include_bytes!("../../fixtures/example-firehose-event.json");
147        let parsed: KinesisFirehoseEvent = serde_json::from_slice(data).unwrap();
148        let output: String = serde_json::to_string(&parsed).unwrap();
149        let reparsed: KinesisFirehoseEvent = serde_json::from_slice(output.as_bytes()).unwrap();
150        assert_eq!(parsed, reparsed);
151    }
152}