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
feat(sns): add SnsSubscriptionMessage for confirmation message types
Add a separate SnsSubscriptionMessage struct for handling SubscriptionConfirmation
and UnsubscribeConfirmation SNS message types. This is a non-breaking change that
keeps the existing SnsMessage struct unchanged.
Changes:
- Add SnsSubscriptionMessage struct with subscribe_url (Option) and token fields
- Add documentation to SnsMessage/SnsMessageObj clarifying they are for Notification only
- Add test fixtures for both SubscriptionConfirmation and UnsubscribeConfirmation
- Add tests verifying deserialization of both confirmation types
The new struct distinguishes confirmation types by:
- sns_message_type field ("SubscriptionConfirmation" or "UnsubscribeConfirmation")
- subscribe_url: Some(url) for SubscriptionConfirmation, None for UnsubscribeConfirmation
Fixes#966
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
/// 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.
99
101
#[serde(alias = "UnsubscribeURL")]
102
+
pubunsubscribe_url:String,
103
+
104
+
/// The Message value specified when the notification was published to the topic.
105
+
pubmessage:String,
106
+
107
+
/// 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)
/// The type of SNS message. Will be "SubscriptionConfirmation" or "UnsubscribeConfirmation".
155
+
#[serde(rename = "Type")]
156
+
pubsns_message_type:String,
157
+
158
+
/// A Universally Unique Identifier, unique for each message published.
159
+
pubmessage_id:String,
160
+
161
+
/// The Amazon Resource Name (ARN) for the topic that this message was published to.
162
+
pubtopic_arn:String,
163
+
164
+
/// The Subject parameter specified when the notification was published to the topic.
100
165
#[serde(default)]
101
-
pubunsubscribe_url:Option<String>,
166
+
pubsubject:Option<String>,
167
+
168
+
/// The time (UTC) when the message was sent.
169
+
pubtimestamp:DateTime<Utc>,
170
+
171
+
/// Version of the Amazon SNS signature used.
172
+
pubsignature_version:String,
173
+
174
+
/// Base64-encoded SHA1withRSA signature of the Message, MessageId, Subject (if present), Type, Timestamp, and TopicArn values.
175
+
pubsignature:String,
102
176
103
-
/// A URL that you can visit to re-confirm the subscription or confirm the unsubscription.
177
+
/// The URL to the certificate that was used to sign the message.
178
+
#[serde(alias = "SigningCertURL")]
179
+
pubsigning_cert_url:String,
180
+
181
+
/// A URL that you can visit to confirm the subscription. Present only for SubscriptionConfirmation messages.
104
182
///
105
-
/// Note: This field is only present in SubscriptionConfirmation and UnsubscribeConfirmation messages.
183
+
/// For UnsubscribeConfirmation messages, this field will be `None`.
106
184
#[serde(alias = "SubscribeURL")]
107
185
#[serde(default)]
108
186
pubsubscribe_url:Option<String>,
109
187
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>,
188
+
/// A value you can use with the ConfirmSubscription action to confirm the subscription.
189
+
/// Alternatively, you can simply visit the `subscribe_url`.
190
+
#[serde(rename = "Token")]
191
+
pubtoken:String,
115
192
116
-
/// The Message value specified when the notification was published to the topic.
193
+
/// The Message value containing a description of the subscription confirmation.
117
194
pubmessage:String,
118
195
119
196
/// 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)
/// Alternate version of `SnsMessage` to use in conjunction with `SnsEventObj<T>` and `SnsRecordObj<T>` for deserializing the message into a struct of type `T`
261
+
/// Alternate version of `SnsMessage` to use in conjunction with `SnsEventObj<T>` and `SnsRecordObj<T>` for deserializing the message into a struct of type `T`.
262
+
///
263
+
/// **Important**: This struct is designed specifically for handling SNS Notification messages
264
+
/// (where `Type` field equals "Notification"). For handling SubscriptionConfirmation or
265
+
/// UnsubscribeConfirmation messages, use [`SnsSubscriptionMessage`] instead.
/// 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.
226
305
#[serde(alias = "UnsubscribeURL")]
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>,
306
+
pubunsubscribe_url:String,
242
307
243
308
/// Deserialized into a `T` from nested JSON inside the SNS message string. `T` must implement the `Deserialize` or `DeserializeOwned` trait.
244
309
#[serde_as(as = "serde_with::json::JsonString")]
@@ -498,41 +563,36 @@ mod test {
498
563
#[test]
499
564
#[cfg(feature = "sns")]
500
565
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
566
+
// Test for issue #966: SnsSubscriptionMessage for SubscriptionConfirmation types
503
567
let data = include_bytes!("../../fixtures/example-sns-subscription-confirmation.json");
504
-
let parsed:SnsEvent = serde_json::from_slice(data).unwrap();
505
-
assert_eq!(1, parsed.records.len());
568
+
let parsed:SnsSubscriptionMessage = 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.",
"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.",
"Message": "You have chosen to deactivate subscription arn:aws:sns:us-east-1:123456789012:MyTopic:00000000-0000-0000-0000-000000000000.\nTo cancel this operation and restore the subscription, visit the SubscribeURL included in this message.",
0 commit comments