Skip to content

scaffoldly/scaffoldly-examples

 
 

Repository files navigation

A Next.js App Running On AWS Lambda (export mode)

GitHub Actions Workflow Status

✨ Quickstart

Run the following command to create your own copy of this application:

npx scaffoldly create app --template node-nextjs-export

Manual Setup

This application was generated with the following command:

npx create-next-app@latest node-nextjs-export

✨ No modifications or SDKs were made or added to the code to "make it work" in AWS Lambda.

Check out our other examples and Learn more at scaffoldly.dev!

Working example

https://jtzom2obx3owx4gn4vluichvze0frzcn.lambda-url.us-east-1.on.aws

First, next.config.mjs was updated

We've set output to be export:

  • export mode creates a Single Page Application (SPA) with no backend
  • The next binary is no longer needed to start the app
const nextConfig = {
  output: "export",
};

Then, Scaffoldly Config was added...

In the project's package.json file, the scaffoldly configuration was added:

  • The serve binary is installed to serve the static HTML
  • The start command now uses serve out to serve the static HTML
{
  "name": "node-nextjs-export",
  "version": "0.1.0",
  // ... snip ...
  "scaffoldly": {
    "runtime": "node:22-alpine",
    "handler": "localhost:3000",
    "packages": ["npm:serve"],
    "services": [
      {
        "name": "next",
        "files": ["package.json", ".next", "out", "package-lock.json"],
        "scripts": {
          "install": "npm ci",
          "dev": "next dev",
          "build": "next build",
          "start": "serve out"
        }
      }
    ]
  }
}

See the Scaffoldly Docs for additional configuration directives.

Then, deployed to AWS Lambda

npx scaffoldly deploy

See the Scaffoldly Docs for details on the scaffoldly deploy command.

After deploy the app is available on a public URL

🚀 Deployment Complete!
   🆔 App Identity: arn:aws:iam::123456789012:role/node-nextjs-export-c2f26520
   📄 Env Files: .env.main, .env
   📦 Image Size: 225.36 MB
   🌎 URL: https://jtzom2obx3owx4gn4vluichvze0frzcn.lambda-url.us-east-1.on.aws

GitHub Action added for CI/CD

A scaffoldly.yml was added to .github/workflows so that a push will trigger a deploy

name: Scaffoldly Deploy

# ... snip ...

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Deploy
        uses: scaffoldly/scaffoldly@v1
        with:
          secrets: ${{ toJSON(secrets) }}

See the Scaffoldly Docs for additional GitHub Actions directives.

Questions, Feedback, and Help

Join our Discussions on GitHub. Join our Community on Discord.

License

This code is licensed under the Apache-2.0 license.

The scaffoldly toolchain is licensed under the FSL-1.1-Apache-2.0 license.

Copyright 2024 Scaffoldly LLC

Contributors 2

  •  
  •