Run Next.js in AWS Lambda

cnuss

Christian Nuss

Posted on October 15, 2024

Run Next.js in AWS Lambda

Want to run a serverless Next.js application in your own AWS Account? Use scaffoldly to build and deploy it!

TL;DR

⭐️ Please give Scaffoldly a star on GitHub ⭐️

Step 0: Create a Next.js project

(If you haven't already!)

npx create-next-app
Enter fullscreen mode Exit fullscreen mode

Step 1: Add scaffoldly to package.json

{
  "name": "node-nextjs",
  "version": "0.1.0",
  // ... snip ...
  "scaffoldly": {
    "runtime": "node:22-alpine",
    "handler": "localhost:3000",
    "services": [
      {
        "name": "next",
        "files": ["package.json", ".next", "node_modules", "package-lock.json"],
        "scripts": {
          "install": "npm ci",
          "build": "next build",
          "start": "next start"
        }
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode
  • The next build script generates the .next folder
  • files lists any files/directories to include in the container
  • Handling different output types in next.config.mjs:

Step 2: Deploy to AWS Lambda using scaffoldly

npx scaffoldly deploy
Enter fullscreen mode Exit fullscreen mode

Example:

 raw `scaffoldly deploy` endraw  output

Scaffoldly will manage or create:

  • IAM Roles
  • ECR Repository
  • Lambda Functions
  • a Function URL

What's next?

⭐️ Please give Scaffoldly a star on GitHub ⭐️

About Scaffoldly

At Scaffoldly, our mission is to empower developers by simplifying the deployment of modern web applications the Cloud. We strive to eliminate the complexities of cloud infrastructure, allowing you to focus on what you do best—building exceptional applications and APIs.

Our Vision

We envision a development ecosystem where deploying to the cloud is as straightforward as running a local development server. By abstracting away the intricacies of cloud infrastructure, Scaffoldly aims to democratize cloud deployment, making it accessible and effortless for developers of all skill levels.

What Scaffoldly Offers

  • Unified Deployment CLI: A single command-line tool that streamlines the deployment of both front-end, back-end, and full-stack applications to AWS Lambda.
  • Seamless Framework Support: Native support for modern frameworks like Next.js, Express, Flask, Golang, Rust without the need for complex configurations.
  • Custom Entrypoints: Proprietary entrypoints that make Next.js and other applications compatible with AWS Lambda's environment.
  • Eliminated Complexity: No more wrestling with Terraform scripts or CloudFormation templates—Scaffoldly handles infrastructure setup using AWS SDK calls.
  • Docker Integration: Efficient packaging of applications into Docker containers, automated and managed within the Scaffoldly CLI.

Learn more at scaffoldly.dev!

💖 💪 🙅 🚩
cnuss
Christian Nuss

Posted on October 15, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Run Next.js in AWS Lambda
lambda Run Next.js in AWS Lambda

October 15, 2024