Run Next.js in AWS Lambda
Christian Nuss
Posted on October 15, 2024
Want to run a serverless Next.js application in your own AWS Account? Use scaffoldly
to build and deploy it!
TL;DR
- See our working example
- See the example project
⭐️ Please give Scaffoldly a star on GitHub ⭐️
Step 0: Create a Next.js project
(If you haven't already!)
npx create-next-app
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"
}
}
]
}
}
- The
next build
script generates the.next
folder -
files
lists any files/directories to include in the container - Handling different
output
types innext.config.mjs
:-
standalone
mode -
export
mode
-
Step 2: Deploy to AWS Lambda using scaffoldly
npx scaffoldly deploy
Example:
Scaffoldly will manage or create:
- IAM Roles
- ECR Repository
- Lambda Functions
- a Function URL
What's next?
- Run
scaffoldly show dockerfile
to show the generatedDockerfile
- Check out our documentation
- See our working example
- See the example project
- Add our GitHub Action to automate your deploys
- Add a Custom Domain to use a memorable URL
- Check out other frameworks that
scaffoldly
supports
⭐️ 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
!
Posted on October 15, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.