pub async fn run_concurrent<A, F, R, B, S, D, E>(
handler: F,
) -> Result<(), Error>where
F: Service<LambdaEvent<A>, Response = R> + Clone + Send + 'static,
F::Future: Future<Output = Result<R, F::Error>> + Send + 'static,
F::Error: Into<Diagnostic> + Debug,
A: for<'de> Deserialize<'de> + Send + 'static,
R: IntoFunctionResponse<B, S> + Send + 'static,
B: Serialize + Send + 'static,
S: Stream<Item = Result<D, E>> + Unpin + Send + 'static,
D: Into<Bytes> + Send + 'static,
E: Into<Error> + Send + Debug + 'static,Available on crate feature
concurrency-tokio only.Expand description
Starts the Lambda Rust runtime in a mode that is compatible with Lambda Managed Instances (concurrent invocations).
Requires the concurrency-tokio feature.
When AWS_LAMBDA_MAX_CONCURRENCY is set to a value greater than 1, this
will spawn AWS_LAMBDA_MAX_CONCURRENCY tokio worker tasks, each running its own
/next polling loop. When the environment variable is unset or <= 1, it
falls back to the same sequential behavior as run, so the same handler
can run on both classic Lambda and Lambda Managed Instances.
If you need more control over the runtime and add custom middleware, use the Runtime type directly.
§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_concurrent(func).await?;
Ok(())
}
async fn func(event: LambdaEvent<Value>) -> Result<Value, Error> {
Ok(event.payload)
}§Panics
This function panics if:
- Called outside of a Tokio runtime
- Required Lambda environment variables are missing (
AWS_LAMBDA_FUNCTION_NAME,AWS_LAMBDA_FUNCTION_MEMORY_SIZE,AWS_LAMBDA_FUNCTION_VERSION,AWS_LAMBDA_RUNTIME_API)