aws_lambda_events 1.1.3

AWS Lambda event definitions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#[cfg(feature = "builders")]
use bon::Builder;
use chrono::{DateTime, Utc};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
#[cfg(feature = "catch-all-fields")]
use serde_json::Value;
use std::collections::HashMap;

use crate::custom_serde::deserialize_nullish;

/// The `Event` notification event handled by Lambda
///
/// [https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html](https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html)
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SnsEvent {
    pub records: Vec<SnsRecord>,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// SnsRecord stores information about each record of a SNS event
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SnsRecord {
    /// A string containing the event source.
    pub event_source: String,

    /// A string containing the event version.
    pub event_version: String,

    /// A string containing the event subscription ARN.
    pub event_subscription_arn: String,

    /// An SNS object representing the SNS message.
    pub sns: SnsMessage,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// SnsMessage stores information about SNS **Notification** type messages only.
///
/// **Important**: This struct is designed specifically for handling SNS Notification messages
/// (where `Type` field equals "Notification"). For handling SubscriptionConfirmation or
/// UnsubscribeConfirmation messages, use [`SnsSubscriptionMessage`] instead.
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SnsMessage {
    /// The type of SNS message. For a lambda event, this should always be **Notification**
    #[serde(rename = "Type")]
    pub sns_message_type: String,

    /// A Universally Unique Identifier, unique for each message published. For a notification that Amazon SNS resends during a retry, the message ID of the original message is used.
    pub message_id: String,

    /// The Amazon Resource Name (ARN) for the topic that this message was published to.
    pub topic_arn: String,

    /// The Subject parameter specified when the notification was published to the topic.
    ///
    /// The SNS Developer Guide states: *This is an optional parameter. If no Subject was specified, then this name-value pair does not appear in this JSON document.*
    ///
    /// Preliminary tests show this appears in the lambda event JSON as `Subject: null`, marking as Option with need to test additional scenarios
    #[serde(default)]
    pub subject: Option<String>,

    /// The time (UTC) when the notification was published.
    pub timestamp: DateTime<Utc>,

    /// Version of the Amazon SNS signature used.
    pub signature_version: String,

    /// Base64-encoded SHA1withRSA signature of the Message, MessageId, Subject (if present), Type, Timestamp, and TopicArn values.
    pub signature: String,

    /// The URL to the certificate that was used to sign the message.
    #[serde(alias = "SigningCertURL")]
    pub signing_cert_url: String,

    /// A URL that you can use to unsubscribe the endpoint from this topic. If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint.
    #[serde(alias = "UnsubscribeURL")]
    pub unsubscribe_url: String,

    /// The Message value specified when the notification was published to the topic.
    pub message: String,

    /// This is a HashMap of defined attributes for a message. Additional details can be found in the [SNS Developer Guide](https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html)
    #[serde(deserialize_with = "deserialize_nullish")]
    #[serde(default)]
    pub message_attributes: HashMap<String, MessageAttribute>,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// SnsSubscriptionMessage stores information about SNS SubscriptionConfirmation and
/// UnsubscribeConfirmation type messages.
///
/// Use this struct when handling messages where the `Type` field equals "SubscriptionConfirmation"
/// or "UnsubscribeConfirmation". For handling Notification messages, use [`SnsMessage`] instead.
///
/// # Distinguishing SubscriptionConfirmation from UnsubscribeConfirmation
///
/// Both message types use this same struct. You can distinguish them by:
/// - Checking the `sns_message_type` field ("SubscriptionConfirmation" or "UnsubscribeConfirmation")
/// - Checking `subscribe_url`: `Some(url)` for SubscriptionConfirmation, `None` for UnsubscribeConfirmation
///
/// # Example
///
/// ```
/// use aws_lambda_events::event::sns::SnsSubscriptionMessage;
///
/// fn handle_confirmation(msg: SnsSubscriptionMessage) {
///     if let Some(url) = &msg.subscribe_url {
///         // SubscriptionConfirmation - visit URL or use token to confirm
///         println!("Confirm subscription at: {}", url);
///     } else {
///         // UnsubscribeConfirmation
///         println!("Unsubscribe confirmed");
///     }
/// }
/// ```
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SnsSubscriptionMessage {
    /// The type of SNS message. Will be "SubscriptionConfirmation" or "UnsubscribeConfirmation".
    #[serde(rename = "Type")]
    pub sns_message_type: String,

    /// A Universally Unique Identifier, unique for each message published.
    pub message_id: String,

    /// The Amazon Resource Name (ARN) for the topic that this message was published to.
    pub topic_arn: String,

    /// The Subject parameter specified when the notification was published to the topic.
    #[serde(default)]
    pub subject: Option<String>,

    /// The time (UTC) when the message was sent.
    pub timestamp: DateTime<Utc>,

    /// Version of the Amazon SNS signature used.
    pub signature_version: String,

    /// Base64-encoded SHA1withRSA signature of the Message, MessageId, Subject (if present), Type, Timestamp, and TopicArn values.
    pub signature: String,

    /// The URL to the certificate that was used to sign the message.
    #[serde(alias = "SigningCertURL")]
    pub signing_cert_url: String,

    /// A URL that you can visit to confirm the subscription. Present only for SubscriptionConfirmation messages.
    ///
    /// For UnsubscribeConfirmation messages, this field will be `None`.
    #[serde(alias = "SubscribeURL")]
    #[serde(default)]
    pub subscribe_url: Option<String>,

    /// A value you can use with the ConfirmSubscription action to confirm the subscription.
    /// Alternatively, you can simply visit the `subscribe_url`.
    #[serde(rename = "Token")]
    pub token: String,

    /// The Message value containing a description of the subscription confirmation.
    pub message: String,

    /// This is a HashMap of defined attributes for a message. Additional details can be found in the [SNS Developer Guide](https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html)
    #[serde(deserialize_with = "deserialize_nullish")]
    #[serde(default)]
    pub message_attributes: HashMap<String, MessageAttribute>,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// An alternate `Event` notification event to use alongside `SnsRecordObj<T>` and `SnsMessageObj<T>` if you want to deserialize an object inside your SNS messages rather than getting an `Option<String>` message
///
/// [https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html](https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html)
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
#[serde(bound(deserialize = "T: DeserializeOwned"))]
pub struct SnsEventObj<T: Serialize> {
    pub records: Vec<SnsRecordObj<T>>,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// Alternative to `SnsRecord`, used alongside `SnsEventObj<T>` and `SnsMessageObj<T>` when deserializing nested objects from within SNS messages)
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
#[serde(bound(deserialize = "T: DeserializeOwned"))]
pub struct SnsRecordObj<T: Serialize> {
    /// A string containing the event source.
    pub event_source: String,

    /// A string containing the event version.
    pub event_version: String,

    /// A string containing the event subscription ARN.
    pub event_subscription_arn: String,

    /// An SNS object representing the SNS message.
    pub sns: SnsMessageObj<T>,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// Alternate version of `SnsMessage` to use in conjunction with `SnsEventObj<T>` and `SnsRecordObj<T>` for deserializing the message into a struct of type `T`.
///
/// **Important**: This struct is designed specifically for handling SNS Notification messages
/// (where `Type` field equals "Notification"). For handling SubscriptionConfirmation or
/// UnsubscribeConfirmation messages, use [`SnsSubscriptionMessage`] instead.
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[serde_with::serde_as]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
#[serde(bound(deserialize = "T: DeserializeOwned"))]
pub struct SnsMessageObj<T: Serialize> {
    /// The type of SNS message. For a lambda event, this should always be **Notification**
    #[serde(rename = "Type")]
    pub sns_message_type: String,

    /// A Universally Unique Identifier, unique for each message published. For a notification that Amazon SNS resends during a retry, the message ID of the original message is used.
    pub message_id: String,

    /// The Amazon Resource Name (ARN) for the topic that this message was published to.
    pub topic_arn: String,

    /// The Subject parameter specified when the notification was published to the topic.
    ///
    /// The SNS Developer Guide states: *This is an optional parameter. If no Subject was specified, then this name-value pair does not appear in this JSON document.*
    ///
    /// Preliminary tests show this appears in the lambda event JSON as `Subject: null`, marking as Option with need to test additional scenarios
    #[serde(default)]
    pub subject: Option<String>,

    /// The time (UTC) when the notification was published.
    pub timestamp: DateTime<Utc>,

    /// Version of the Amazon SNS signature used.
    pub signature_version: String,

    /// Base64-encoded SHA1withRSA signature of the Message, MessageId, Subject (if present), Type, Timestamp, and TopicArn values.
    pub signature: String,

    /// The URL to the certificate that was used to sign the message.
    #[serde(alias = "SigningCertURL")]
    pub signing_cert_url: String,

    /// A URL that you can use to unsubscribe the endpoint from this topic. If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint.
    #[serde(alias = "UnsubscribeURL")]
    pub unsubscribe_url: String,

    /// Deserialized into a `T` from nested JSON inside the SNS message string. `T` must implement the `Deserialize` or `DeserializeOwned` trait.
    #[serde_as(as = "serde_with::json::JsonString")]
    #[serde(bound(deserialize = "T: DeserializeOwned"))]
    pub message: T,

    /// This is a HashMap of defined attributes for a message. Additional details can be found in the [SNS Developer Guide](https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html)
    #[serde(deserialize_with = "deserialize_nullish")]
    #[serde(default)]
    pub message_attributes: HashMap<String, MessageAttribute>,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

/// Structured metadata items (such as timestamps, geospatial data, signatures, and identifiers) about the message.
///
/// Message attributes are optional and separate from—but are sent together with—the message body. The receiver can use this information to decide how to handle the message without having to process the message body first.
///
/// Additional details can be found in the [SNS Developer Guide](https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html)
#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct MessageAttribute {
    /// The data type of the attribute. Per the [SNS Developer Guide](https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html), lambda notifications, this will only be **String** or **Binary**.
    #[serde(rename = "Type")]
    pub data_type: String,

    /// The user-specified message attribute value.
    #[serde(rename = "Value")]
    pub value: String,

    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CloudWatchAlarmPayload {
    pub alarm_name: String,
    pub alarm_description: String,
    #[serde(rename = "AWSAccountId")]
    pub aws_account_id: String,
    pub new_state_value: String,
    pub new_state_reason: String,
    pub state_change_time: String,
    pub region: String,
    pub alarm_arn: String,
    pub old_state_value: String,
    pub trigger: CloudWatchAlarmTrigger,
    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CloudWatchAlarmTrigger {
    pub period: i64,
    pub evaluation_periods: i64,
    pub comparison_operator: String,
    pub threshold: f64,
    pub treat_missing_data: String,
    pub evaluate_low_sample_count_percentile: String,
    #[serde(default)]
    pub metrics: Vec<CloudWatchMetricDataQuery>,
    pub metric_name: Option<String>,
    pub namespace: Option<String>,
    pub statistic_type: Option<String>,
    pub statistic: Option<String>,
    pub unit: Option<String>,
    #[serde(default)]
    pub dimensions: Vec<CloudWatchDimension>,
    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CloudWatchMetricDataQuery {
    pub id: String,
    pub expression: Option<String>,
    pub label: Option<String>,
    pub metric_stat: Option<CloudWatchMetricStat>,
    pub period: Option<i64>,
    #[serde(default, deserialize_with = "deserialize_nullish")]
    pub return_data: bool,
    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CloudWatchMetricStat {
    pub metric: CloudWatchMetric,
    pub period: i64,
    pub stat: String,
    pub unit: Option<String>,
    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CloudWatchMetric {
    #[serde(default)]
    pub dimensions: Vec<CloudWatchDimension>,
    pub metric_name: Option<String>,
    pub namespace: Option<String>,
    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[non_exhaustive]
#[cfg_attr(feature = "builders", derive(Builder))]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct CloudWatchDimension {
    pub name: String,
    pub value: String,
    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
    /// Enabled with Cargo feature `catch-all-fields`.
    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
    #[cfg(feature = "catch-all-fields")]
    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
    #[serde(flatten)]
    #[cfg_attr(feature = "builders", builder(default))]
    pub other: serde_json::Map<String, Value>,
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_event() {
        let data = include_bytes!("../../fixtures/example-sns-event.json");
        let parsed: SnsEvent = serde_json::from_slice(data).unwrap();
        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsEvent = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_event_pascal_case() {
        let data = include_bytes!("../../fixtures/example-sns-event-pascal-case.json");
        let parsed: SnsEvent = serde_json::from_slice(data).unwrap();
        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsEvent = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_event_cloudwatch_single_metric() {
        let data = include_bytes!("../../fixtures/example-cloudwatch-alarm-sns-payload-single-metric.json");
        let parsed: SnsEvent = serde_json::from_slice(data).unwrap();
        assert_eq!(1, parsed.records.len());

        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsEvent = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);

        let parsed: SnsEventObj<CloudWatchAlarmPayload> =
            serde_json::from_slice(data).expect("failed to parse CloudWatch Alarm payload");

        let record = parsed.records.first().unwrap();
        assert_eq!("EXAMPLE", record.sns.message.alarm_name);
    }

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_event_cloudwatch_multiple_metrics() {
        let data = include_bytes!("../../fixtures/example-cloudwatch-alarm-sns-payload-multiple-metrics.json");
        let parsed: SnsEvent = serde_json::from_slice(data).unwrap();
        assert_eq!(2, parsed.records.len());

        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsEvent = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_obj_event() {
        let data = include_bytes!("../../fixtures/example-sns-event-obj.json");

        #[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
        struct CustStruct {
            foo: String,
            bar: i32,
        }

        let parsed: SnsEventObj<CustStruct> = serde_json::from_slice(data).unwrap();
        println!("{parsed:?}");

        assert_eq!(parsed.records[0].sns.message.foo, "Hello world!");
        assert_eq!(parsed.records[0].sns.message.bar, 123);

        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsEventObj<CustStruct> = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_subscription_confirmation() {
        // Test for issue #966: SnsSubscriptionMessage for SubscriptionConfirmation types
        let data = include_bytes!("../../fixtures/example-sns-subscription-confirmation.json");
        let parsed: SnsSubscriptionMessage = serde_json::from_slice(data).unwrap();

        assert_eq!("SubscriptionConfirmation", parsed.sns_message_type);
        assert!(parsed.subscribe_url.is_some());
        assert_eq!(
            "https://sns.us-east-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-1:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e2425dacbbffff",
            parsed.subscribe_url.as_ref().unwrap()
        );
        assert_eq!("2336412f37fb687f5d51e6e2425dacbbffff", parsed.token);

        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsSubscriptionMessage = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }

    #[test]
    #[cfg(feature = "sns")]
    fn my_example_sns_unsubscribe_confirmation() {
        // Test for UnsubscribeConfirmation messages - subscribe_url should be None
        let data = include_bytes!("../../fixtures/example-sns-unsubscribe-confirmation.json");
        let parsed: SnsSubscriptionMessage = serde_json::from_slice(data).unwrap();

        assert_eq!("UnsubscribeConfirmation", parsed.sns_message_type);
        assert!(parsed.subscribe_url.is_none());
        assert_eq!("2336412f37fb687f5d51e6e2425dacbbeeee", parsed.token);

        let output: String = serde_json::to_string(&parsed).unwrap();
        let reparsed: SnsSubscriptionMessage = serde_json::from_slice(output.as_bytes()).unwrap();
        assert_eq!(parsed, reparsed);
    }
}