Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 922639e

Browse files
authored
Make SNS signature optional (#115)
* feat: make sns signature optional * feat: add unsigned sns example * test: add unsigned sns test
1 parent bf6a7b2 commit 922639e

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Records": [
3+
{
4+
"EventVersion": "1.0",
5+
"EventSubscriptionArn": "arn:aws:sns:EXAMPLE",
6+
"EventSource": "aws:sns",
7+
"Sns": {
8+
"Type" : "Notification",
9+
"MessageId" : "f5458878-95d1-5aad-82d9-d3d5edf775d9",
10+
"SequenceNumber" : "10000000000000027000",
11+
"TopicArn" : "arn:aws:sns:eu-central-1:xxx:dev-events.fifo",
12+
"Message" : "{\"foo\":\"Hello world!\",\"bar\":123}",
13+
"Timestamp" : "2022-09-27T22:15:02.834Z",
14+
"UnsubscribeURL" : "https://sns.eu-central-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-central-1:xxx:dev-events.fifo:aab561d9-73b3-4cdf-b527-9cbfa357eb47"
15+
}
16+
}
17+
]
18+
}

aws_lambda_events/src/sns/mod.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ pub struct SnsMessageObj<T: Serialize> {
134134
pub timestamp: DateTime<Utc>,
135135

136136
/// Version of the Amazon SNS signature used.
137-
pub signature_version: String,
137+
pub signature_version: Option<String>,
138138

139139
/// Base64-encoded SHA1withRSA signature of the Message, MessageId, Subject (if present), Type, Timestamp, and TopicArn values.
140-
pub signature: String,
140+
pub signature: Option<String>,
141141

142142
/// The URL to the certificate that was used to sign the message.
143143
#[serde(rename = "SigningCertURL")]
144-
pub signing_cert_url: String,
144+
pub signing_cert_url: Option<String>,
145145

146146
/// 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.
147147
#[serde(rename = "UnsubscribeURL")]
@@ -239,4 +239,26 @@ mod test {
239239
let reparsed: SnsEventObj<CustStruct> = serde_json::from_slice(output.as_bytes()).unwrap();
240240
assert_eq!(parsed, reparsed);
241241
}
242+
243+
#[test]
244+
#[cfg(feature = "sns")]
245+
fn my_example_sns_obj_unsigned_event() {
246+
let data = include_bytes!("../generated/fixtures/example-sns-event-obj-unsigned.json");
247+
248+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
249+
struct CustStruct {
250+
foo: String,
251+
bar: i32,
252+
}
253+
254+
let parsed: SnsEventObj<CustStruct> = serde_json::from_slice(data).unwrap();
255+
println!("{:?}", parsed);
256+
257+
assert_eq!(parsed.records[0].sns.message.foo, "Hello world!");
258+
assert_eq!(parsed.records[0].sns.message.bar, 123);
259+
260+
let output: String = serde_json::to_string(&parsed).unwrap();
261+
let reparsed: SnsEventObj<CustStruct> = serde_json::from_slice(output.as_bytes()).unwrap();
262+
assert_eq!(parsed, reparsed);
263+
}
242264
}

0 commit comments

Comments
 (0)