0.3.2 • Published 3 years ago

nextjs-faas v0.3.2

Weekly downloads
32
License
ISC
Repository
github
Last release
3 years ago

NextJS FaaS CLI

This project modifies a serverless NextJS build to add in a compatibility layer for AWS Lambda together with a handler that handles routing.

The standard handler reacts to Application Load Balancer events but it also has an alternative handler for API Gateway V2.

Warning: this is still early software and only supports SSR pages, static generation is still a work in progress

Usage

Add this plugin to your NextJS project as a dev dependency with either of the following commands:

# npm
npm install nextjs-faas --save-dev

# yarn
yarn add -D nextjs-faas

Next up add the plugin to your next.config.js:

nextjs-faas build --provider=aws-lambda <project-path> output/

After the build two folders will be available in the default output/ build folder.

  • lambda/ contains the code and should be uploaded to a lambda function
  • assets/ contains the assets that should be uploaded to a S3 bucket

Note: To properly access static files, it's best to set an asset prefix to your s3 bucket

Setting the correct handler

The build exports two lambda handlers

  • index.handler is the default and should be invocated by an Application Load Balancer
  • index.ApiGatewayHandler is an alternative that can be invocated by Api Gateway V2

Thanks

A lot of the code has been made available by the serverless-next.js project, major thanks for all their work.