You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(sns): support SubscriptionConfirmation and UnsubscribeConfirmation message types
The SnsMessage and SnsMessageObj structs were failing to deserialize
SubscriptionConfirmation and UnsubscribeConfirmation SNS messages because:
1. `unsubscribe_url` was required (String) but these message types don't have it
2. `subscribe_url` and `token` fields were missing entirely
This fix:
- Makes `unsubscribe_url` optional (Option<String>) since it's only present
in Notification messages
- Adds `subscribe_url` field (Option<String>) for confirmation messages
- Adds `token` field (Option<String>) for confirmation messages
All fields use #[serde(default)] to handle missing fields gracefully.
Fixes#966
Signed-off-by: abhu85 <151518127+abhu85@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: lambda-events/src/event/sns/mod.rs
+75-2Lines changed: 75 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -94,8 +94,24 @@ pub struct SnsMessage {
94
94
pubsigning_cert_url:String,
95
95
96
96
/// 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.
97
+
///
98
+
/// Note: This field is only present in Notification messages. It is not present in SubscriptionConfirmation or UnsubscribeConfirmation messages.
97
99
#[serde(alias = "UnsubscribeURL")]
98
-
pubunsubscribe_url:String,
100
+
#[serde(default)]
101
+
pubunsubscribe_url:Option<String>,
102
+
103
+
/// A URL that you can visit to re-confirm the subscription or confirm the unsubscription.
104
+
///
105
+
/// Note: This field is only present in SubscriptionConfirmation and UnsubscribeConfirmation messages.
106
+
#[serde(alias = "SubscribeURL")]
107
+
#[serde(default)]
108
+
pubsubscribe_url:Option<String>,
109
+
110
+
/// A value you can use with the ConfirmSubscription action to re-confirm the subscription.
111
+
///
112
+
/// Note: This field is only present in SubscriptionConfirmation and UnsubscribeConfirmation messages.
113
+
#[serde(default)]
114
+
pubtoken:Option<String>,
99
115
100
116
/// The Message value specified when the notification was published to the topic.
/// 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.
224
+
///
225
+
/// Note: This field is only present in Notification messages. It is not present in SubscriptionConfirmation or UnsubscribeConfirmation messages.
208
226
#[serde(alias = "UnsubscribeURL")]
209
-
pubunsubscribe_url:String,
227
+
#[serde(default)]
228
+
pubunsubscribe_url:Option<String>,
229
+
230
+
/// A URL that you can visit to re-confirm the subscription or confirm the unsubscription.
231
+
///
232
+
/// Note: This field is only present in SubscriptionConfirmation and UnsubscribeConfirmation messages.
233
+
#[serde(alias = "SubscribeURL")]
234
+
#[serde(default)]
235
+
pubsubscribe_url:Option<String>,
236
+
237
+
/// A value you can use with the ConfirmSubscription action to re-confirm the subscription.
238
+
///
239
+
/// Note: This field is only present in SubscriptionConfirmation and UnsubscribeConfirmation messages.
240
+
#[serde(default)]
241
+
pubtoken:Option<String>,
210
242
211
243
/// Deserialized into a `T` from nested JSON inside the SNS message string. `T` must implement the `Deserialize` or `DeserializeOwned` trait.
212
244
#[serde_as(as = "serde_with::json::JsonString")]
@@ -462,4 +494,45 @@ mod test {
462
494
let reparsed:SnsEventObj<CustStruct> = serde_json::from_slice(output.as_bytes()).unwrap();
463
495
assert_eq!(parsed, reparsed);
464
496
}
497
+
498
+
#[test]
499
+
#[cfg(feature = "sns")]
500
+
fnmy_example_sns_subscription_confirmation(){
501
+
// Test for issue #966: SnsMessage struct fails with SubscriptionConfirmation types
502
+
// SubscriptionConfirmation messages have SubscribeURL and Token fields instead of UnsubscribeURL
503
+
let data = include_bytes!("../../fixtures/example-sns-subscription-confirmation.json");
504
+
let parsed:SnsEvent = serde_json::from_slice(data).unwrap();
"Message": "You have chosen to subscribe to the topic arn:aws:sns:us-east-1:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
0 commit comments