Lambda function

Discover the Lambda function preset with Nitro to deploy Nuxt to any lambda-compatible serverless platform.

Lambda function - 图1

Back to presets list.

Usage

You can use the Nuxt config to explicitly set the preset to use:

nuxt.config.js|ts

  1. export default {
  2. nitro: {
  3. preset: 'aws-lambda'
  4. }
  5. }

Or directly use the NITRO_PRESET environment variable when running nuxt build:

  1. NITRO_PRESET=lambda npx nuxt build

AWS Lambda defaults to payload version v2. This Nitro preset supports both v1 and v2 payloads.

Entry point

When running nuxt build with the Lambda preset, the result will be an entry point that exports a handler function that responds to an event and returns a response.

This entry point is compatible with AWS Lambda and Netlify Functions.

It can be used programmatically or as part of a deployment.

  1. import { handler } from './.output/server'
  2. // Use programmatically
  3. const { statusCode, headers, body } = handler({ rawPath: '/' })