Skip to content

Commit 96c1db3

Browse files
committed
Tidied up test-lambda
1 parent 5de3fb7 commit 96c1db3

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

test-lambda/src/main.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// This is a basic lambda for testing the emulator locally.
2-
use lambda_runtime::{service_fn, Error, LambdaEvent};
2+
use lambda_runtime::{service_fn, Error, LambdaEvent, Runtime};
33
use serde::{Deserialize, Serialize};
44
use tracing::info;
55

@@ -17,32 +17,31 @@ struct Response {
1717
#[tokio::main]
1818
async fn main() -> Result<(), Error> {
1919
// minimal logging to keep it simple
20+
// intended to run locally only
2021
tracing_subscriber::fmt()
21-
.compact()
2222
.without_time()
23-
.with_ansi(true)
23+
.with_ansi(true) // the color codes work in the terminal only
2424
.with_target(false)
2525
.init();
2626

27-
let func = service_fn(my_handler);
28-
lambda_runtime::run(func).await?;
27+
// init the runtime directly to avoid the extra logging layer
28+
let runtime = Runtime::new(service_fn(my_handler));
29+
runtime.run().await?;
30+
2931
Ok(())
3032
}
3133

3234
pub(crate) async fn my_handler(event: LambdaEvent<Request>) -> Result<Response, Error> {
33-
info!("Received event: {:?}", event);
35+
info!("Handler invoked");
3436

35-
// extract some useful info from the request
3637
let command = event.payload.command;
3738

3839
info!("Command received: {}", command);
3940

40-
// prepare the response
41-
let resp = Response {
41+
Ok(Response {
4242
req_id: event.context.request_id,
43-
msg: format!("Command {} executed.", command),
44-
};
43+
msg: "Hello from Rust!".to_string(),
44+
})
4545

46-
// return `Response` (it will be serialized to JSON automatically by the runtime)
47-
Ok(resp)
46+
// Err(Error::from("Error"))
4847
}

0 commit comments

Comments
 (0)