pub fn handler_runtime<H, Args>(handler: H) -> LambdaHandlerService<H, Args>
Expand description
Wraps an async handler in a runtime environment for processing AWS Lambda events.
This function creates a LambdaHandlerService
that integrates the provided handler with an AWS Lambda-compatible runtime.
The handler is an async function responsible for processing incoming requests and generating responses.
§Type Parameters
H
: The type of the handler. It must be a function or type that implements theHandler
trait.Args
: The type representing the arguments passed to the handler. It must implement theFromRequest
trait.
§Parameters
handler
: An async function or handler type that processes requests in the Lambda runtime. The handler should be an async function or struct that implements theHandler
trait.
§Constraints
H
:H::Future
:H::Output
:- Must implement
Respondable
, allowing the handler’s output to be transformed into a valid Lambda response.
- Must implement
Args
:- Must implement the
FromRequest
trait to handle the conversion of incoming requests into theArgs
type. - Must be both
Send
andSync
to ensure safe concurrent access and use in the Lambda environment. - Must have a
'static
lifetime to ensure it does not contain any non-static references.
- Must implement the
Args::Error
:- Must be
Send
to ensure errors can be safely sent across threads.
- Must be
§Returns
A LambdaHandlerService
instance that processes incoming Lambda events using the provided handler.
§Examples
use titan::{web, Respondable};
async fn my_handler(body_str: String) -> impl Respondable {
"Hello World"
}
#[tokio::main]
async fn main() {
// Uncomment the last line to run example
titan_lambda::handler_runtime(my_handler).run(); // .await.unwrap();
}
§See Also
Handler
: For the handler trait that your async function must implement.FromRequest
: For handling the conversion of incoming data into request types.Respondable
: For handling the conversion of response data into a Lambda-compatible format.LambdaHandlerService
: For the service that integrates the handler with AWS Lambda.
§Errors
Any errors that arise during request processing or handler execution will be propagated through the LambdaHandlerService
.