pub async fn run_actix_on_lambda<F, I, S, B>(
    factory: F
) -> Result<(), LambdaError>where
    F: Fn() -> I + Send + Clone + 'static,
    I: IntoServiceFactory<S, Request>,
    S: ServiceFactory<Request, Config = AppConfig, Response = ServiceResponse<B>, Error = Error> + 'static,
    S::InitError: Debug,
    B: MessageBody,
    B::Error: Display,
    <B as MessageBody>::Error: Debug,
Expand description

Run Actix web application on AWS Lambda

use lambda_web::actix_web::{self, get, App, HttpServer, Responder};
use lambda_web::{is_running_on_lambda, run_actix_on_lambda, LambdaError};

#[get("/")]
async fn hello() -> impl Responder {
    format!("Hello")
}

#[actix_web::main]
async fn main() -> Result<(),LambdaError> {
    let factory = move || {
        App::new().service(hello)
    };
    if is_running_on_lambda() {
        // Run on AWS Lambda
        run_actix_on_lambda(factory).await?;
    } else {
        // Run local server
        HttpServer::new(factory).bind("127.0.0.1:8080")?.run().await?;
    }
    Ok(())
}