-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathmain.rs
More file actions
31 lines (25 loc) · 837 Bytes
/
main.rs
File metadata and controls
31 lines (25 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use lambda_runtime::{
service_fn,
streaming::{channel, Body, Response},
tracing, Error, LambdaEvent,
};
use aws_lambda_json_impl::Value;
use std::{thread, time::Duration};
async fn func(_event: LambdaEvent<Value>) -> Result<Response<Body>, Error> {
let messages = vec!["Hello", "world", "from", "Lambda!"];
let (mut tx, rx) = channel();
tokio::spawn(async move {
for message in messages.iter() {
tx.send_data((message.to_string() + "\n").into()).await.unwrap();
thread::sleep(Duration::from_millis(500));
}
});
Ok(Response::from(rx))
}
#[tokio::main]
async fn main() -> Result<(), Error> {
// required to enable CloudWatch error logging by the runtime
tracing::init_default_subscriber();
lambda_runtime::run(service_fn(func)).await?;
Ok(())
}