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 (#1102)
* 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>
* 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>
* docs(sns): remove ignore from SnsSubscriptionMessage example
The doc example compiles as-is, so the ignore attribute is unnecessary.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Signed-off-by: abhu85 <151518127+abhu85@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: abhu85 <abhu85@users.noreply.github.com>
/// 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.
165
+
#[serde(default)]
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,
176
+
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.
182
+
///
183
+
/// For UnsubscribeConfirmation messages, this field will be `None`.
184
+
#[serde(alias = "SubscribeURL")]
185
+
#[serde(default)]
186
+
pubsubscribe_url:Option<String>,
187
+
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,
192
+
193
+
/// The Message value containing a description of the subscription confirmation.
194
+
pubmessage:String,
195
+
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)
/// 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
/// 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.
"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