DEV Community

Cover image for Run Next.js in AWS Lambda
Christian Nuss
Christian Nuss

Posted on

1 1 1 1 1

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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more