How to Deploy a Next.js App on AWS: A Step-by-Step Guide

Deploy your Next.js app to AWS with ease using Microtica’s one-click deployment for a fast, secure, and scalable solution.

MNMarija NaumovskaUpdated 4 min read

Next.js is a go-to framework for modern web apps: hybrid static and server rendering, built-in TypeScript support, and performance features like smart bundling and route prefetching. It builds on React and is tuned for production, which makes it a solid base for fast, SEO-friendly sites.

This guide deploys a Next.js app from your own repository to your AWS account with Microtica. The app runs on Amazon ECS with AWS Fargate, behind an HTTPS load balancer, and every push to your branch deploys it again. You don’t need a Dockerfile or a Kubernetes cluster.

Two Ways to Deploy

  • Ask Mica. Paste your repository’s URL into Mica. It reads the code, proposes how to build and run it, and deploys once you approve. Getting started shows that flow.
  • Set it up yourself. The add flow asks one question at a time and shows everything it will do before it does it. The rest of this guide follows it.

Both end in the same place: your app on Amazon ECS in your AWS account, with a pipeline that deploys every push.

Before You Start

You need:

  • A Microtica account. Sign up with your email or a Git account.
  • Your Next.js app in GitHub, GitLab or Bitbucket. A standard app with build and start scripts works as it is. If the repository has a Dockerfile at its root, Microtica builds with it; otherwise Railpack detects Next.js and builds the image for you.
  • An AWS account. You connect it to your environment during the deploy, if it isn’t connected yet.

Two details about the app itself. Microtica passes the port as the PORT environment variable, and next start listens on it, so you don’t need to change anything. And the load balancer checks that / answers with a 200, so make sure your home page doesn’t redirect to a login.

How to Deploy a Next.js App to AWS

Step 1: Add a service from your repository

Open Apps in the environment you want, for example development, and choose Add. Pick A service from your repository, and Microtica asks where the code comes from.

  1. Acme Store
  2. Add
Sample data
Pick Your repository to deploy an app you already have.

Choose Your repository.

Step 2: Choose Amazon ECS

Amazon ECS is the recommended runtime. It needs no cluster, runs in your AWS account with HTTPS, and scales with traffic.

  1. Acme Store
  2. Add
Sample data
Amazon ECS needs no cluster. Kubernetes needs one in the environment first.

Kubernetes is the other option. It needs a cluster in the environment first. If you want that route, the React on Kubernetes guide walks through creating one.

Step 3: Pick the repository and branch

Choose the Git account, the repository and the branch. Every push to that branch deploys to this environment.

  1. Acme Store
  2. Add
Sample data
Pick the repository and the branch. Every push to it deploys.

If no Git account is connected yet, the step offers to connect one. Deploying on push needs a webhook, so the account needs owner, admin or maintainer rights on the repository.

Step 4: Name it

Microtica suggests a name from the repository: letters and numbers, starting with a letter. It’s the app’s name in Microtica and in your AWS account.

  1. Acme Store
  2. Add
Sample data
Name the app. Next.js reads the port from PORT, so the default 8080 works.

Under Settings, the port defaults to 8080. Keep it for Next.js, since the app reads PORT.

Step 5: Review and deploy

The review shows the app, its code and branch, where it runs and how it builds. Below that, What happens next lists every action in order. Nothing changes until you press Create and deploy.

  1. Acme Store
  2. Add
Sample data
No Dockerfile? Railpack detects Next.js and builds the image.

If the environment has no AWS account, Microtica asks you to connect one first. The first app in an environment also sets up Amazon ECS there, once for all its apps. Nothing is committed to your repository.

Step 6: Open your app

The same page follows the setup: Amazon ECS in the environment, the app’s resources, then the first build and deploy. When it’s done, the app’s HTTPS address appears.

  1. Acme Store
  2. Add
Sample data
Once the first build deploys, the app answers at its HTTPS address.

You can leave the page while it runs. Open the run shows the build log, and the Open link with your app’s name takes you to its page.

After the First Deploy

  • Updates. Push to the branch and Microtica builds and deploys the new version. Amazon ECS rolls it out gradually and rolls back on its own if the new version starts returning server errors.
  • Scaling. The app runs between one and three tasks and scales with CPU load.
  • Logs and failures. The app’s page shows its status, and each build has its log on the run page. When a build or deploy fails, ask Mica to look into it.
  • Secrets. Keep API keys and credentials out of the repository and give them to the app as environment variables at runtime.

Performance Tips for Production

  • Cache static assets. Next.js fingerprints its build output, so set long cache headers on /_next/static. For a global audience, put a CDN such as Amazon CloudFront in front of the app.
  • Prefer static and incremental pages. Pages Next.js can pre-render cost no server time per request. Use server rendering where the data really changes per request.
  • Watch the health check. If a deploy never becomes healthy, check that / answers quickly with a 200 and that the app listens on PORT.

Conclusion

Deploying a Next.js app on AWS takes a repository and a few answers: where the code is, which branch, and a name. Microtica builds it without a Dockerfile, runs it on Amazon ECS in your own AWS account with HTTPS, and ships every push. Your time goes into the app, not the infrastructure.

Put your first app online.

Paste a repository, approve the plan, and your app is live in your own cloud account.