Skip to content

Commit e59b81b

Browse files
committed
Sample Amazon SQS function code using Rust without batch item handling.
1 parent 4f92047 commit e59b81b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

integration-sqs-to-lambda/main.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use aws_lambda_events::event::sqs::SqsEvent;
2+
use lambda_runtime::{run, service_fn, Error, LambdaEvent};
3+
4+
static UNDEFINED: &str = "undefined";
5+
6+
async fn function_handler(event: LambdaEvent<SqsEvent>) -> Result<(), Error> {
7+
8+
event.payload.records.iter().for_each(|record| {
9+
// process the record
10+
tracing::info!("Message body: {}", record.body.as_deref().unwrap_or(UNDEFINED))
11+
});
12+
13+
Ok(())
14+
}
15+
16+
#[tokio::main]
17+
async fn main() -> Result<(), Error> {
18+
tracing_subscriber::fmt()
19+
.with_max_level(tracing::Level::INFO)
20+
// disable printing the name of the module in every log line.
21+
.with_target(false)
22+
// disabling time is handy because CloudWatch will add the ingestion time.
23+
.without_time()
24+
.init();
25+
26+
run(service_fn(function_handler)).await
27+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@
9696
"language": "go"
9797
}
9898
]
99+
},
100+
{
101+
"id": "Rust",
102+
"title": "Usage Example with Rust:",
103+
"description": "Sample Amazon SQS function code using Rust without batch item handling.",
104+
"snippets": [
105+
{
106+
"snippetPath": "main.rs",
107+
"language": "rust"
108+
}
109+
]
99110
}
100111
]
101112
}

0 commit comments

Comments
 (0)