# Deploy a Next.js app on AWS --- Deployment.io builds your Next.js app from its repository and serves it from Amazon S3 and CloudFront in your own AWS account. ## Before you start - The app is in a GitHub, GitLab or Bitbucket repository that's connected to Deployment.io. See [Adding a Repository](/docs/dashboard/adding-a-repository/). - The app must be a static export. In `next.config.js` (or `next.config.mjs`) set `output: 'export'` and `trailingSlash: true`. If it uses `next/image`, also set `images: { unoptimized: true }`. Features that need a server — API routes, middleware, server-side rendering at request time, incremental static regeneration — don't work in a static export. ## Deployment 1. Create a new Static site on Deployment.io. 2. Select your app's repository. 3. Build command: `npm run build`. 4. Publish directory: `out`. 5. Single-page app: No. 6. Root directory: leave it empty unless the app lives in a subfolder of the repository (a monorepo). Then enter that folder. 7. Choose the Environment and click Deploy static site. Your site is available at the CloudFront URL shown in the dashboard once the build finishes. See [Adding Custom Domains](/docs/dashboard/adding-custom-domains/) and [Automatic Deployment on Git Push](/docs/dashboard/automatic-deployment-on-git-push/). ## How the build runs Deployment.io installs the app's dependencies before the build command, with the package manager its lockfile names — npm (`package-lock.json`), Yarn (`yarn.lock`) or pnpm (`pnpm-lock.yaml`). A `packageManager` field in `package.json` is honoured. So the build command is only the build itself — don't add an install step. Builds run on Node.js 22, and `package.json` must be at the top of the repository or of the Root directory. ## Environment variables The environment's variables are available to the build. Next.js puts only variables with the `NEXT_PUBLIC_` prefix into the code that runs in the browser. Anything in a static site's build is public — never put a secret there. ## Routing `trailingSlash: true` makes Next.js write each page as `/index.html`, which is how Deployment.io serves a page's address: `/about` redirects to `/about/`, which serves `about/index.html`. Without it, pages other than the home page don't load. With Single-page app set to No, an address with no page shows the site's `404.html` with a 404 status, and an address without a trailing slash (such as `/about`) redirects to the one with it (`/about/`). If the site was already deployed with Yes, change the setting on its Settings tab; it applies on the next deploy. --- Source: https://deployment.io/docs/guides/how-to-deploy-nextjs-app-on-aws/