Search
Return to News

The Observatory

Next.js on AWS

May 23, 2023

Next.js is a popular open-source framework for building modern web applications.

It allows developers to create server-rendered React applications easily, which improves performance and SEO. Amazon Web Services (AWS) is one of the most popular cloud computing platforms that provides a vast range of services. In this blog, we’ll explore one of the many ways to use Next.js with AWS and give some example sites.

Getting Started

Deploying a Next.js application to AWS can be done in several ways including using AWS EC2, AWS Amplify Hosting, AWS Elastic Beanstalk and AWS Lambda. The steps below describe creating and running a Next.js app on an EC2 instance.

NOTE: This is a brief overview of the necessary steps and may vary depending on your setup.  

Step 1: Create an EC2 Instance

The first step is to create an EC2 instance. This can be done through the AWS Management Console. Select the appropriate region, choose an Amazon Machine Image (AMI) that supports Next.js, and select the appropriate instance type. You can choose the amount of resources you need depending on your app’s requirements.

Step 2: Configure Security Group

The next step is to configure a security group. A security group acts as a virtual firewall that controls inbound and outbound traffic for your instance. You need to add rules that allow traffic on port 80 and 443 for HTTP and HTTPS traffic, respectively.

Step 3: Connect to the Instance

You can connect to the instance using SSH. To do this, navigate to the EC2 dashboard and locate the instance you created. Click the “Connect” button and follow the instructions to connect to the instance using SSH.

Step 4: Install Node.js and NPM

Before you can run your Next.js app, you need to install Node.js and NPM on your EC2 instance. You can do this by running the following commands:

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

Step 5: Clone Your Next.js App

Once you have Node.js and NPM installed, you can clone your Next.js app from your Git repository to your EC2 instance. You can use Git to clone the repository by running the following command:

git clone <repository_url>

Step 6: Install Dependencies

Next, you need to install the dependencies for your Next.js app. You can do this by navigating to the root directory of your app and running the following command:

npm install

Step 7: Build Your App

Once you have installed the dependencies, you need to build your Next.js app. You can do this by running the following command:

npm run build

This command will create a production-ready version of your app in the .next directory.

Step 8: Start Your App

Finally, you can start your Next.js app by running the following command:

npm run start

This will start your app on the default port. If you want to run your app on a specific port, you can specify it using the PORT environment variable. For example:

PORT=8080 npm run start

This will start your app on port 8080.

Step 9: Configure Your Domain

To configure your domain, you need to create a DNS record that points to your EC2 instance’s public IP address. You can do this through your domain registrar or DNS provider.

Step 10: Configure HTTPS

Finally, you need to configure HTTPS for your app. You can do this by obtaining an SSL/TLS certificate and configuring your server to use it. You can use the AWS Certificate Manager to obtain a free SSL/TLS certificate. Once you have obtained the certificate, you can configure your server to use it by following the instructions in the Next.js documentation.

Summary

Using Next.js with AWS can provide developers with a powerful toolset to build fast, efficient, and scalable web applications. AWS offers a wide range of services that can be used in conjunction with Next.js, including AWS EC2, AWS Amplify Hosting, AWS Elastic Beanstalk, AWS Lambda, and others. By following the steps outlined above, you can easily deploy your Next.js application to AWS and take advantage of its cloud-based infrastructure. With this integration, you can create robust web applications that are highly scalable and easy to maintain. So, give it a try, and let us know what you think!

Examples

Here are some public examples of websites that have been built using Next.js and deployed on AWS:

  1. Uber: Uber’s engineering team has used Next.js for several of their projects, including Uber’s new driver app. They use AWS Lambda to handle their serverless functions and AWS CloudFront to deliver content to users.
  2. adidas: Adidas, the multinational corporation that designs and manufactures athletic and casual footwear, apparel, and accessories, has rebuilt its eCommerce platform using Next.js and AWS. They use AWS Lambda and AWS API Gateway to handle their serverless functions, and AWS CloudFront to deliver their content globally.
  3. HashiCorp: HashiCorp, a cloud infrastructure automation company, uses Next.js and AWS Lambda to build and deploy their website. They also use AWS S3 and AWS CloudFront to deliver their content globally.
  4. Marvel: Marvel, the popular comic book publisher, uses Next.js and AWS Lambda to build and deploy their website. They also use AWS S3 and AWS CloudFront to deliver their content globally.
  5. AccuWeather: AccuWeather, the popular weather forecasting website, uses Next.js and AWS Lambda to build and deploy their website. They also use AWS S3 and AWS CloudFront to deliver their content globally.

These are just a few examples of the many websites that have been built using Next.js and deployed on AWS. By using Next.js with AWS, developers can build fast, efficient, and scalable web applications that can handle large amounts of traffic and deliver content globally.

Interested in reading more from the Carimus team?Here are some related stories

Dynamic Experiences, Statically Generated

JouleBug Beyond Sustainability

Contact Us

Carimus Icon