Skip to content

Commit 23e96ab

Browse files
authored
Merge pull request #103 from joyofhex/add_rust_sns_to_lambda_snippet
Add Rust snippet for integration-sns-to-lambda
2 parents 9b2970a + 74f026d commit 23e96ab

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use aws_lambda_events::event::sns::SnsEvent;
2+
use aws_lambda_events::sns::SnsRecord;
3+
use lambda_runtime::{run, service_fn, Error, LambdaEvent};
4+
use tracing::info;
5+
6+
// Built with the following dependencies:
7+
// aws_lambda_events = { version = "0.10.0", default-features = false, features = ["sns"] }
8+
// lambda_runtime = "0.8.1"
9+
// tokio = { version = "1", features = ["macros"] }
10+
// tracing = { version = "0.1", features = ["log"] }
11+
// tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
12+
13+
async fn function_handler(event: LambdaEvent<SnsEvent>) -> Result<(), Error> {
14+
for event in event.payload.records {
15+
process_record(&event)?;
16+
}
17+
18+
Ok(())
19+
}
20+
21+
fn process_record(record: &SnsRecord) -> Result<(), Error> {
22+
info!("Processing SNS Message: {}", record.sns.message);
23+
24+
// Implement your record handling code here.
25+
26+
Ok(())
27+
}
28+
29+
#[tokio::main]
30+
async fn main() -> Result<(), Error> {
31+
tracing_subscriber::fmt()
32+
.with_max_level(tracing::Level::INFO)
33+
.with_target(false)
34+
.without_time()
35+
.init();
36+
37+
run(service_fn(function_handler)).await
38+
}

integration-sns-to-lambda/snippet-data.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Using an Amazon SNS trigger to invoke a Lambda function",
44
"type": "Integration",
55
"services": ["lambda", "sns"],
6-
"languages": ["Node", "Python", ".NET", "TypeScript"],
6+
"languages": ["Node", "Python", ".NET", "TypeScript", "Rust"],
77
"tags": [],
88
"introBox": {
99
"headline": "How it works",
@@ -74,6 +74,17 @@
7474
"language": "py"
7575
}
7676
]
77+
},
78+
{
79+
"id": "Rust",
80+
"title": "Usage Example with Rust:",
81+
"description": "Consuming an SNS event with Lambda using Rust.",
82+
"snippets": [
83+
{
84+
"snippetPath": "lambda-sns-receive.rs",
85+
"language": "rust"
86+
}
87+
]
7788
}
7889
]
7990
}

0 commit comments

Comments
 (0)