1
1
/// 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 } ;
3
3
use serde:: { Deserialize , Serialize } ;
4
4
use tracing:: info;
5
5
@@ -17,32 +17,31 @@ struct Response {
17
17
#[ tokio:: main]
18
18
async fn main ( ) -> Result < ( ) , Error > {
19
19
// minimal logging to keep it simple
20
+ // intended to run locally only
20
21
tracing_subscriber:: fmt ( )
21
- . compact ( )
22
22
. without_time ( )
23
- . with_ansi ( true )
23
+ . with_ansi ( true ) // the color codes work in the terminal only
24
24
. with_target ( false )
25
25
. init ( ) ;
26
26
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
+
29
31
Ok ( ( ) )
30
32
}
31
33
32
34
pub ( crate ) async fn my_handler ( event : LambdaEvent < Request > ) -> Result < Response , Error > {
33
- info ! ( "Received event: {:?}" , event ) ;
35
+ info ! ( "Handler invoked" ) ;
34
36
35
- // extract some useful info from the request
36
37
let command = event. payload . command ;
37
38
38
39
info ! ( "Command received: {}" , command) ;
39
40
40
- // prepare the response
41
- let resp = Response {
41
+ Ok ( Response {
42
42
req_id : event. context . request_id ,
43
- msg : format ! ( "Command {} executed." , command ) ,
44
- } ;
43
+ msg : "Hello from Rust!" . to_string ( ) ,
44
+ } )
45
45
46
- // return `Response` (it will be serialized to JSON automatically by the runtime)
47
- Ok ( resp)
46
+ // Err(Error::from("Error"))
48
47
}
0 commit comments