This repository provides a quick and easy way to deploy a simple Next.js app router application on AWS Lambda using aws-lambda-web-adapter.
Before you start, ensure that you have the following prerequisites installed:
In your Next.js app, update the next.config.js
file to build the application for standalone deployment by adding output: 'standalone'
. Additionally, include the assetPrefix
property to specify the CDN DOMAIN for serving static files:
const nextConfig = {
output: 'standalone',
assetPrefix: 'https://<CDN_DOMAIN>',
// other code
}
- Clone this repository
https://github.com/annleefores/nextjs13-lambda.git
cd nextjs13-lambda
- Navigate to the deploy script
cd packages/deploy
- Install dependencies
npm i
- Build deploy script
npm run build
- To run deploy script in dev mode
npm run dev
- Create
terraform.tfvars
file based on theterraform.tfvars.example
example file - Follow the comments to add required values
terraform.tfvars
must be present in tf folder for the script to work- You can also use any of the env variable methods for Terraform listed here
- Build and deploy application
cd path/to/my/nextjs/app
node path/to/nextjs13-lambda/packages/deploy/build/deploy.js deploy
- Delete deployment
cd path/to/nextjs-app
node path/to/nextjs13-lambda/packages/deploy/build/deploy.js delete
- Building application
cd path/to/my/nextjs/app
node path/to/nextjs13-lambda/packages/deploy/build/deploy.js build
cd examples # from root directory
node ../packages/deploy/build/deploy.js <command>