pub async fn run<A, F, R, B, S, D, E>(handler: F) -> Result<(), Error>where
F: Service<LambdaEvent<A>, Response = R>,
F::Future: Future<Output = Result<R, F::Error>>,
F::Error: Into<Diagnostic> + Debug,
A: for<'de> Deserialize<'de>,
R: IntoFunctionResponse<B, S>,
B: Serialize,
S: Stream<Item = Result<D, E>> + Unpin + Send + 'static,
D: Into<Bytes> + Send,
E: Into<Error> + Send + Debug,Expand description
Starts the Lambda Rust runtime and begins polling for events on the Lambda Runtime APIs.
If you need more control over the runtime and add custom middleware, use the Runtime type directly.
§Managed concurrency
If AWS_LAMBDA_MAX_CONCURRENCY is set, a warning is logged.
If your handler can satisfy Clone + Send + 'static,
prefer run_concurrent (requires the concurrency-tokio feature),
which honors managed concurrency and falls back to sequential behavior when
unset.
§Example
use lambda_runtime::{Error, service_fn, LambdaEvent};
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<(), Error> {
let func = service_fn(func);
lambda_runtime::run(func).await?;
Ok(())
}
async fn func(event: LambdaEvent<Value>) -> Result<Value, Error> {
Ok(event.payload)
}§Panics
This function panics if required Lambda environment variables are missing
(AWS_LAMBDA_FUNCTION_NAME, AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
AWS_LAMBDA_FUNCTION_VERSION, AWS_LAMBDA_RUNTIME_API).