> ## Documentation Index
> Fetch the complete documentation index at: https://nestrs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# nestrs-lambda

> Run a nestrs Axum router on AWS Lambda and API Gateway — NestJS serverless analogue without Fastify or Express.

NestJS serverless guides wrap Express or Fastify. nestrs is Axum-only ([ADR-0001](https://github.com/Joshyahweh/nestrs/blob/main/docs/src/adrs/0001-axum-only.md)). `nestrs-lambda` takes the router from `NestApplication::into_router` and serves it with [`lambda_http`](https://docs.rs/lambda_http) (API Gateway HTTP API, REST API, ALB, Function URL).

## Install

```toml theme={null}
[dependencies]
nestrs = "1.3.0"
nestrs-lambda = "1.3.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

The crate enables `lambda_http` features `apigw_http` and `apigw_rest`.

## Listen on Lambda

Do **not** call `listen` / `listen_graceful`. Those bind a TCP socket. On Lambda, hand the router to `listen_lambda`:

```rust theme={null}
use nestrs::prelude::*;
use nestrs_lambda::{lambda_http, listen_lambda};

#[module(controllers = [HealthController], providers = [AppState])]
struct AppModule;

#[derive(Default)]
#[injectable]
struct AppState;

#[controller(prefix = "/health")]
struct HealthController;

#[routes(state = AppState)]
impl HealthController {
    #[get("/")]
    async fn live() -> &'static str {
        "ok"
    }
}

#[tokio::main]
async fn main() -> Result<(), lambda_http::Error> {
    let router = NestFactory::create::<AppModule>().into_router();
    listen_lambda(router).await
}
```

## Local vs Lambda

| Environment         | Entry point                                               |
| ------------------- | --------------------------------------------------------- |
| Process / container | `NestFactory::create::<M>().listen_graceful(3000)`        |
| AWS Lambda          | `listen_lambda(NestFactory::create::<M>().into_router())` |

Share the same `AppModule`. Swap only `main`.

<Warning>
  `PathNormalization` and some listen-only builders apply in `listen`, not `into_router`. If you rely on trailing-slash rewriting, wrap the router yourself after `into_router`.
</Warning>

## API

| Item                    | Role                               |
| ----------------------- | ---------------------------------- |
| `listen_lambda(router)` | `lambda_http::run(router).await`   |
| `lambda_http`           | Re-export of the AWS runtime crate |
