Cover image for How to Deploy a Next.js App Using SST (Serverless Stack)
Peter k
0 min read

Deploying a Next.js application using SST (Serverless Stack) is a powerful approach to leverage AWS's serverless infrastructure while keeping the deployment simple and scalable. SST simplifies the setup of resources like Lambda functions, API Gateway, and more. Here’s how you can do it step by step:

1. Install SST

First, you need to have the SST CLI installed. You can do this globally via npm:

npm install -g sst

Create an SST App

Create a new SST project by running the following command:

npx create-sst@latest

Follow the prompts to set up a new project. This will generate the necessary project structure for an SST app.

3. Add Next.js to the Project

After creating the SST project, install Next.js by navigating into your project folder and running:

npm install next react react-dom

Next, add your Next.js app to the src directory. You can either create a new app using npx create-next-app or move an existing Next.js app into the folder.

4. Update stacks/MyStack.js

SST uses AWS CDK under the hood. To deploy your Next.js app, modify stacks/MyStack.js to use NextjsSite, which makes it easier to integrate with Lambda and API Gateway.

Conclusion

Deploying a Next.js app with SST makes it easy to take full advantage of AWS's serverless architecture. By using Lambda and API Gateway, your application is automatically scalable and cost-effective. With a few simple commands and configurations, SST streamlines the entire deployment process, allowing you to focus on your app rather than the infrastructure.