Software Development

Deploy Next.js to AWS using SST

Save Money and Win Control over Your Next.js Apps

Deploy Next.js to AWS using SST
This image has been generated by AI.

If you want to save money with hosting, and learn valuable skills like CI/CD, then this article is for you.

You will learn useful AWS skills, CI/CD pipelines using Github Actions, all of which are in-demand skills that pay very well in the industry.

AWS is not as challenging as it seems when using SST, which configures the necessary AWS services to host your Next.js apps with ease.

So without further ado… Let’s dive right in!

1. Configuring AWS

Most tutorials on SST skip this step; they assume you know how to do this already.

This article is different.

I will not cut any corners, and I will explain the entire process so you can avoid searching thousands of articles to look for answers.


Configuring AWS consists of three main steps:

  1. Create an AWS Account
  2. Create an IAM User
  3. Set Up the AWS CLI

Create an AWS Account

Creating an AWS account is very straightforward. Here is the link to register.

If you need further assistance, Ashok IT explains the account creation process in just 2 minutes:

Create an IAM User

Now we need to create an IAM (Identity and Access Management) user to allow us to programmatically interact with AWS.

This process was daunting at first, but this article by SST explains this process extremely well using pictures at every step.

After you are finished, make sure to copy your Access key and Secret Access Key somewhere safe. This is necessary for the next step.

Set Up the AWS CLI

The installation process differs for Windows and Unix operating systems, so I will make sure to cover both:

Windows Installation

In Windows, you can run the following command in Powershell or CMD:

After completing the installation process, you can verify that the CLI works by restarting your terminal and running aws --version.

Unix Installation

1. Make sure both python and pip are installed on your system.

2. Install the awscli package by running this command:


Now run aws configure, and enter the Access Key ID and Secret Access Key from the previous section on Creating an IAM User.

2. Configuring SST for Next.js

1. Before we begin, make sure you have a Next.js app by running the following command:

2. cd into your project directory, and run the following command to initialize SST:

3. Create a file called .env.local, then add the AWS key and secret:

4. Find the sst.config.ts file in the root of your project directory, then configure it with any settings you want.

Here is my config file as a reference:

3. Creating a CI/CD Pipeline With Github Actions

Now that we have setup AWS, bootstrapped SST with Next.js, we are ready to deploy our application using a CI/CD (Continuous Integration/Continuous Integration) pipeline.

A CI/CD pipeline is a set of predefined commands that are executed sequentially on a remote computer (when you push changes to Github).

These commands typically consist of setting up node.js, installing dependencies, and deployment.


To get started, create a new folder called .github/workflows in the root of your directory, then add a file called deploy.yml.

I encourage you to read all of the comments (#) in this file for a better understanding of how all this works:

If you need more help with this, be sure to leave me a comment and I will help you promptly.


You may have noticed in the last comment I talked about "Github Secrets", so lets configure that now.

1. Start by following this URL:

https://github.com/<GITHUB-NAME>/<YOUR-REPO>/settings/secrets/actions

Make sure to replace <YOUR-REPO> and <GITHUB-NAME>

2. Copy your environment variables from your .env.local file into Github Secrets.


You should now be able to commit and push your changes, then watch your application deploy on this page:

https://github.com/<GITHUB-NAME>/<YOUR-REPO>/actions

NOTE: This process can take up to 10 minutes for the first deployment. If you encounter any bugs during this process, please let me know so I can help you.

4. Next Steps

Congratulations! You should now have a Next.js app running on AWS!

Your application should be hosted on a Cloudfront distribution.

Your next step should be to point your custom domain to your Cloudfront Distribution, and I recommend following this guide to understand how to do this properly.

Also feel free to ask for help.

I have implemented this myself, and I am happy to help. 😉


If you enjoyed this article, please make sure to Subscribe, Clap, Comment and Connect with me today! 🌐

References