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 theHandlertrait.Args: The type representing the arguments passed to the handler. It must implement theFromRequesttrait.
§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 theHandlertrait.
§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
FromRequesttrait to handle the conversion of incoming requests into theArgstype. - Must be both
SendandSyncto ensure safe concurrent access and use in the Lambda environment. - Must have a
'staticlifetime to ensure it does not contain any non-static references.
- Must implement the
Args::Error:- Must be
Sendto 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.