6
6
//! implementation to the Lambda runtime to run as a Lambda function. By using Axum instead
7
7
//! of a basic `tower::Service` you get web framework niceties like routing, request component
8
8
//! extraction, validation, etc.
9
- use std:: env:: set_var;
10
9
use axum:: http:: StatusCode ;
11
- use lambda_http:: {
12
- run,
13
- Error ,
14
- } ;
15
10
use axum:: {
16
11
extract:: Path ,
17
12
response:: Json ,
18
- Router ,
19
13
routing:: { get, post} ,
14
+ Router ,
20
15
} ;
21
- use serde_json:: { Value , json} ;
16
+ use lambda_http:: { run, Error } ;
17
+ use serde_json:: { json, Value } ;
18
+ use std:: env:: set_var;
22
19
23
20
async fn root ( ) -> Json < Value > {
24
21
Json ( json ! ( { "msg" : "I am GET /" } ) )
@@ -36,12 +33,12 @@ async fn post_foo_name(Path(name): Path<String>) -> Json<Value> {
36
33
Json ( json ! ( { "msg" : format!( "I am POST /foo/:name, name={name}" ) } ) )
37
34
}
38
35
39
- /// Example on how to return status codes and data from a Axum function
40
- async fn health_check ( ) -> ( StatusCode , & str ) {
36
+ /// Example on how to return status codes and data from an Axum function
37
+ async fn health_check ( ) -> ( StatusCode , & ' static str ) {
41
38
let healthy = false ;
42
- match health {
43
- true => { ( StatusCode :: OK , "Healthy!" ) } ,
44
- false => { ( StatusCode :: INTERNAL_SERVER_ERROR , "Not healthy!" ) }
39
+ match healthy {
40
+ true => ( StatusCode :: OK , "Healthy!" ) ,
41
+ false => ( StatusCode :: INTERNAL_SERVER_ERROR , "Not healthy!" ) ,
45
42
}
46
43
}
47
44
@@ -51,7 +48,7 @@ async fn main() -> Result<(), Error> {
51
48
// Remove if you want the first section of the url to be the stage name of the API Gateway
52
49
// i.e with: `GET /test-stage/todo/id/123` without: `GET /todo/id/123`
53
50
set_var ( "AWS_LAMBDA_HTTP_IGNORE_STAGE_IN_PATH" , "true" ) ;
54
-
51
+
55
52
// required to enable CloudWatch error logging by the runtime
56
53
tracing_subscriber:: fmt ( )
57
54
. with_max_level ( tracing:: Level :: INFO )
0 commit comments