How does it work?

When calling open-next build, OpenNext runs next build to build the Next.js app, and then transforms the build output to a format that can be deployed to AWS.

Building the Next.js app

OpenNext runs the build script in your package.json file. Depending on the lock file found in the app, the corresponding packager manager will be used. Either npm run build, yarn build, or pnpm build will be run. For more on customizing the build command, see overriding the build command.

Transforming the build output

The build output is then transformed into a format that can be deployed to AWS. The transformed output is generated inside the .open-next folder within your Next.js app. Files in assets/ are ready to be uploaded to AWS S3. And the function code is wrapped inside Lambda handlers, ready to be deployed to AWS Lambda or Lambda@Edge.

my-next-app/
  .open-next/
    cache/                         -> ISR cache files to upload - This cannot be directly served
    assets/                        -> Static files to upload
    server-functions/
      default/                     -> Handler code for the default server
      other-fn/                    -> Handler code for another backend
    revalidation-function/         -> Handler code for revalidation backend
    image-optimization-function/   -> Handler code for image optimization backend
    warmer-function/               -> Cron job code to keep server function warm - Not mandatory
    dynamo-provider/               -> Code for a custom resource to populate the Tag Cache - Only necessary for app dir