

# Steps to migrate your app

These are the steps to move a web app from Amplify Hosting to AWS Amplify. Start with the checks. After Step 8, transfer your custom domain.

## What changes
<a name="migrate-what-changes"></a>


| Amplify Hosting | Amplify | 
| --- | --- | 
| Branch (each connected branch is a deployment target) | Environment. Every app has `preview` and `production`, and you can add custom environments. Each environment tracks one or more branches. | 
| Build | Deployment. Each deployment builds and deploys your app and gets its own URL. Each environment serves one deployment at a time. | 
|  `amplify.yml` build specification |  `amplify.jsonc` in your repository root | 
| Domain association: one root domain and its subdomains | One custom domain per hostname. `<your-domain>` and `www.<your-domain>` are separate domains. | 
| Rewrites, redirects, custom headers, password protection |  `routes`, a domain setting, your framework config, and access control. See Step 6 and Step 2. | 

## Check whether your app can migrate
<a name="migrate-who"></a>

This guide moves the hosting of a web app that Amplify Hosting builds and serves. It does not move an Amplify Gen 1 or Gen 2 backend. If your `amplify.yml` has a `backend` section, your app has an Amplify backend.


| Your app on Amplify Hosting | What to do | 
| --- | --- | 
| Amplify Gen 2 backend (`amplify/backend.ts`, deployed with `npx ampx pipeline-deploy`) | Move the frontend and keep the backend. Deploy the backend from your own CI. The Amplify build reads its outputs. See [Deploy with an Amplify Gen 2 backend](build-with-amplifygen3-amplify-gen2-backend.md). The backend stays linked to your Amplify Hosting app ID and branch, so keep the Amplify Hosting app when you decommission, instead of deleting it. | 
| Amplify Gen 1 backend (`amplify/backend/` folder, deployed with `amplifyPush`) | Not covered here. Keep the app on Amplify Hosting. | 
| Next.js, Nuxt, Astro, or SvelteKit, at a supported version | Move it. For the versions, see [Frameworks](server-side-rendering-amplify.md). | 
| An earlier version of one of these frameworks, including every Next.js app on the `WEB_DYNAMIC` platform | Upgrade the framework first. | 
| Astro or SvelteKit with a community adapter, for example `astro-aws-amplify` or `amplify-adapter`  | Move it, and replace the community adapter with the Amplify adapter (see Step 3). | 
| Another server-rendered framework deployed with a deployment specification (`deploy-manifest.json`), for example Remix, React Router, Angular SSR, or Express | Amplify has no adapter for it. If the app can build as a static site, move it as one. Otherwise, keep it on Amplify Hosting. | 
| Static site or single-page app | Move it. A single-page app uses `spa_fallback` for client-side routes (see Step 6). A static site can’t set custom headers. | 
| Rules that reuse part of the matched path in the target (for example `/blog/<*>` to `/articles/<*>`), a redirect that passes the query string on, a reverse proxy to an external URL, a custom 404 page, or custom headers | Not possible in `routes`. Move these rules into the framework config of a Next.js, Nuxt, Astro, or SvelteKit app (see Step 6). A static site or single-page app that needs them stays on Amplify Hosting for now. | 
| A Large (16 GiB) or XLarge (72 GiB) build instance | Amplify can’t build the app. Keep it on Amplify Hosting, or build in your own CI and deploy the output with `aws amplifygen3 deploy --prebuilt`. To check your size, run the command after this table. `STANDARD_8GB`, or no value, is the default size. | 
| Automatic subdomains for branches, wildcard subdomains, or your own certificate from outside AWS Certificate Manager | No equivalent yet. | 
| Deploys from Bitbucket or AWS CodeCommit | No equivalent yet. Deploy from your CI instead. | 

To get your build instance size, replace `<your-amplify-hosting-app-id>` with your Amplify Hosting app ID:

```bash
aws amplify get-app --app-id <your-amplify-hosting-app-id> --query 'app.jobConfig.buildComputeType'
```

For more information, see [AWS Amplify (Amplify Gen 3) and Amplify Hosting compared](amplify-gen3-vs-amplify-hosting.md).

## Prerequisites
<a name="migrate-prerequisites"></a>
+ AWS credentials for the AWS account that owns your Amplify Hosting app, and permissions for Amplify. To check your credentials, run `aws sts get-caller-identity`. If the command fails, sign in with `aws sso login` or `aws configure`. For the permissions, see [Give your account permissions](security_iam_id-based-policy-examples.md#setup-permissions).
+ The latest version of the AWS Command Line Interface (AWS CLI) v2, which includes the `aws amplifygen3` subcommand. To check, run `aws amplifygen3 help`. If the command isn’t found, install or update the AWS CLI by following [Installing or updating to the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) in the *AWS CLI User Guide*.
+ A framework that Amplify supports, at a supported version, or a static site. For the list, see [Frameworks](server-side-rendering-amplify.md). Amplify builds your app and runs its server-side code on Node.js 24, so build and test your app on Node.js 24.
+ (Optional) `jq`, to export environment variables from the command line in Step 4.

Amplify commands run against the Region configured for your AWS CLI. Look for your Amplify metrics and alarms (Step 8) in that Region.

## Before you begin: review your Amplify Hosting settings
<a name="migrate-before-you-begin"></a>

Collect your Amplify Hosting settings first. You recreate them in the steps that follow.

### Review settings in the console
<a name="migrate-byb-console"></a>

1. Open the Amplify Hosting console and choose your app.

1. In the navigation pane, choose **Hosting**, then review **Build settings**, **Environment variables**, **Rewrites and redirects**, **Custom headers**, **Custom domains**, and **Access control**.

1. On the app overview page, note the connected branches and which one is production.

### Export settings using the CLI
<a name="migrate-byb-cli"></a>

Replace `<your-amplify-hosting-app-id>` with your Amplify Hosting app ID, then run the following commands:

```bash
export AMPLIFY_HOSTING_APP_ID=<your-amplify-hosting-app-id>

aws amplify get-app --app-id $AMPLIFY_HOSTING_APP_ID > amplify-hosting-app.json
aws amplify list-branches --app-id $AMPLIFY_HOSTING_APP_ID > amplify-hosting-branches.json
aws amplify list-domain-associations --app-id $AMPLIFY_HOSTING_APP_ID > amplify-hosting-domains.json
```
+  `amplify-hosting-app.json` holds the build specification (`buildSpec`), app-level environment variables (`environmentVariables`), redirects and rewrites (`customRules`), custom headers (`customHeaders`), and app-wide password protection (`enableBasicAuth`).
+  `amplify-hosting-branches.json` holds each branch’s variable overrides and password protection (`branches[].enableBasicAuth`).
+  `amplify-hosting-domains.json` maps each subdomain to a branch.

If your Amplify Hosting app isn’t in your default AWS Region, add `--region <region>` to each `aws amplify` command in this guide.

An `amplify.yml` or `customHttp.yml` file in your repository takes precedence over the console settings, so read those too.

Secrets aren’t in these files. Find them in the Amplify Hosting console under **Hosting**, **Secrets**.

Note your production branch (it becomes the `production` environment), the branch each subdomain serves, every variable and secret, every redirect, rewrite, and header rule, and the password-protected branches.

Done when: you have your branches, domains, variables, secrets, rules, and access settings on hand.

## Step 1: Create the Amplify app
<a name="migrate-step-1"></a>

Create the Amplify app from the same repository or source code. The Amplify Hosting app is not affected.

### Create the app using the CLI
<a name="migrate-step-1-cli"></a>

From the root of your repository, run the following command. Replace `<app-name>` with a name for your Amplify app:

```bash
aws amplifygen3 create --name <app-name> --git .
```

 `create` creates the app and its IAM roles, connects the repository, and writes `amplify.jsonc`. It doesn’t deploy. `--git .` reads the URL from your local `origin` remote. If `origin` is an SSH URL, `create` converts it to HTTPS. Commit `amplify.jsonc`.

For a monorepo, add `--filter` with the folder that your app lives in:

```bash
aws amplifygen3 create --name <app-name> --git . --filter apps/web
```

Run the `aws amplifygen3` commands in this guide from your repository root. They read the app name from `amplify.jsonc`. From another folder, add `--app <app-name>`. Otherwise the command takes the app name from `package.json`, or from the folder name if there’s no `package.json`. `deploy` asks you to confirm that name, and in CI, where nobody can answer, it fails. In CI, pass `--app`.

### Create the app in the console
<a name="migrate-step-1-console"></a>

1. Sign in to the Amplify console.

1. Choose **GitHub** or **GitLab** as your app source, allow access, and choose the repository and your production branch.

1. Check the install command, build command, and output directory. For a monorepo, set **Root directory**. Add the environment variables and secrets from Before you begin. Amplify deploys your app as soon as you create it, so the first build fails if it needs a variable that isn’t set yet.

1. Choose **Create and deploy**.

The console deploys your app to the `production` environment right away, at a URL anyone can open. If your Amplify Hosting app is password protected, use the CLI instead, and turn on access control (Step 2) before anything is deployed.

**Note**  
Repositories in Bitbucket or AWS CodeCommit can’t be connected. Create the app without `--git`, and deploy from your own CI as shown in Step 5.

**Note**  
If your Amplify Hosting app uses manual deploys (drag and drop, Amazon S3, or a URL), create the app without `--git`. Deploy from your source folder with `aws amplifygen3 deploy`. To deploy output you’ve already built, run `aws amplifygen3 deploy --prebuilt`. It uploads the folder set in `deploy.output_directory` by default, or a folder or zip file you name with `--prebuilt <path>`. Skip Step 5.

Done when: the app exists and `amplify.jsonc` is in your repository.

## Step 2: Recreate password protection
<a name="migrate-step-2"></a>

Amplify Hosting protects branches with a shared user name and password. In Amplify, visitors sign in through IAM Identity Center or your own OpenID Connect (OIDC) provider before they can view a protected environment.

Amplify apps and every deployment URL are public until you turn on access control. If any branch was password protected, do this step before your first deployment. Access control needs an identity provider to sign visitors in. Before you start, either enable IAM Identity Center in your account or have an OIDC provider ready. You choose which one to use in the next step. Without one, enabling access control fails, and your environments stay public.

### Turn on access control using the CLI
<a name="migrate-step-2-cli"></a>

Choose an identity source, then enable access control. For OIDC, replace `<issuer-url>` and `<client-id>` with your provider’s values:

```bash
# Sign in with your IAM Identity Center users
aws amplifygen3 access-control edit --type team

# Or with your own OIDC provider (prompts for the client secret)
aws amplifygen3 access-control edit --type oidc --issuer <issuer-url> --client-id <client-id> --client-secret

# Protect every environment that maps to a protected branch
aws amplifygen3 access-control enable --env preview --env production
```

Run `access-control enable` again for each environment you create in Step 5, for example `--env staging`.

### Turn on access control in the console
<a name="migrate-step-2-console"></a>

1. Choose your app, then **Settings**, **Access control**.

1. Choose **Enable for new environment**, then choose the environment.

1. Choose the identity source, **Team** (IAM Identity Center) or **OIDC**. For OIDC, enter your provider’s details.

1. Choose who can sign in, then enable it. Repeat for each environment that needs protection.

Done when: each environment that maps to a protected branch has access control on.

## Step 3: Move build settings
<a name="migrate-step-3"></a>

Map your `amplify.yml` onto the install and build commands in `amplify.jsonc`:


|  `amplify.yml`  | Amplify | 
| --- | --- | 
|  `frontend.phases.preBuild.commands`  |  `deploy.install` in `amplify.jsonc`  | 
|  `frontend.phases.build.commands`  |  `deploy.build`. For Next.js, keep the adapter command that `create` writes. It runs your `build` script (see Framework adapters). | 
|  `frontend.artifacts.baseDirectory`  |  `deploy.output_directory`  | 
|  `frontend.cache.paths`  | Not needed. Build caching is enabled by default. | 
|  `appRoot` or `AMPLIFY_MONOREPO_APP_ROOT`  | Root directory (`aws amplifygen3 app edit --root-dir`, or **Root directory** in the console) | 

If a phase runs several commands, join them with `&&` in one string, or move them into a `package.json` script.

### Framework adapters
<a name="migrate-step-3-adapters"></a>

 `create` detects your framework and writes `deploy.install`, `deploy.build`, and `deploy.output_directory` to `amplify.jsonc`. It picks the install and build commands for your package manager (pnpm, Yarn, npm, or Bun) from your lock file. Keep the values it writes.
+  **Next.js.** The adapter is the build command, `npx @aws-amplifygen3/adapter-nextjs`, with output directory `.amplify`. You install nothing.
+  **Nuxt, Astro, and SvelteKit.** `create` offers to install the adapter package (`[Y/n]`). Pass `--yes` to accept. A shell with no input, such as an agent’s shell or CI, declines. `create` then prints the step that is left: add the adapter to your framework config by hand. `create` never edits the framework config. `deploy` makes the same offer when `amplify.jsonc` has no `deploy` block (`--allow-install` accepts it). If you replace a community adapter, remove it from your framework config.
+  **Static site.** `create` writes your build script and its output folder, for example `dist`.

For example, `amplify.jsonc` for a Next.js app, where `<app-name>` is your app’s name:

```json
{
  "name": "<app-name>",
  "deploy": {
    "install": "npm ci",
    "build": "npx @aws-amplifygen3/adapter-nextjs",
    "output_directory": ".amplify"
  },
  "env": {
    "preview": {},
    "production": {}
  }
}
```

### Change build settings
<a name="migrate-step-3-change"></a>

Edit `deploy` in `amplify.jsonc` and commit it. Values in `amplify.jsonc` override the app settings at deploy time. For an app created in the console without `amplify.jsonc`, change the app settings instead:
+ Console: choose your app, then **Settings**, **Build settings**. Under **Source configuration**, choose **Edit**.
+ CLI: `aws amplifygen3 app edit --install-command "npm ci" --build-command "npm run build" --output-dir "dist"`. For Next.js, keep the adapter build command.

### Build limits
<a name="migrate-step-3-limits"></a>


| Amplify Hosting | Amplify | 
| --- | --- | 
| Build timeout configurable up to 120 minutes | Up to 1 hour per build. New AWS accounts start with lower quotas. | 
| Custom build image, live package updates (for example a pinned Node.js version) | Not available. Builds and server-side code run on Node.js 24. | 

Limits such as apps, concurrent deployments, custom environments, and build time depend on your billing plan. For the current limits, see [Quotas](quotas-chapter.md). Run `npm run build` locally before your first deploy to catch build errors early.

Done when: `deploy.install`, `deploy.build`, and `deploy.output_directory` in `amplify.jsonc` match your old build settings.

## Step 4: Move environment variables and secrets
<a name="migrate-step-4"></a>

Copy your Amplify Hosting variables and secrets to each Amplify environment. In Amplify Hosting, app-level variables apply to every branch, and branch overrides replace them. Upload the app-level variables to every environment first, and the overrides second. Don’t copy build-control variables such as `_LIVE_UPDATES`, `_BUILD_TIMEOUT`, and `AMPLIFY_MONOREPO_APP_ROOT`. They do nothing in Amplify.

### Copy variables in the console
<a name="migrate-step-4-console"></a>

1. In the Amplify Hosting console, choose your app, then **Hosting**, **Environment variables**. Note each variable and any per-branch overrides.

1. In the Amplify console, choose your app, then **Settings**. For **Environment variables**, choose **Add**, then **Bulk input**.

1. Paste the app-level variables, one `KEY=value` per line, and choose **Parse variables**. Mark each sensitive value as a secret.

1. Choose every environment, then choose **Add and deploy**.

1. Repeat for each branch’s overrides, choosing only the environment that branch maps to.

### Copy variables using the CLI
<a name="migrate-step-4-cli"></a>

Export the variables to `.env` files with `jq`:

```bash
# App-level variables
aws amplify get-app --app-id $AMPLIFY_HOSTING_APP_ID \
  --query 'app.environmentVariables' --output json \
  | jq -r '(. // {}) | to_entries[] | select(.key | test("^(_|AMPLIFY_)") | not) | select(.value != "") | "\(.key)=\(.value | @json)"' \
  > .env.amplify-hosting

# Overrides for one branch, for example main
aws amplify get-branch --app-id $AMPLIFY_HOSTING_APP_ID --branch-name main \
  --query 'branch.environmentVariables' --output json \
  | jq -r '(. // {}) | to_entries[] | select(.key | test("^(_|AMPLIFY_)") | not) | select(.value != "") | "\(.key)=\(.value | @json)"' \
  > .env.amplify-hosting.main
```

The `jq` filter skips build-control variables and empty values, and quotes each value so values with `#`, quotes, or line breaks upload intact. It also skips any variable of your own that starts with `AMPLIFY_`, so add those back by hand. Review the files, and add any secrets you keep outside Amplify Hosting.

Then upload them. Replace `<SECRET_NAME>` with the name of a secret you keep outside Amplify Hosting:

```bash
# 1. App-level variables to every environment
aws amplifygen3 var upload .env.amplify-hosting --env production
aws amplifygen3 var upload .env.amplify-hosting --env preview

# 2. Branch overrides to the matching environment
aws amplifygen3 var upload .env.amplify-hosting.main --env production

# 3. Secrets you keep outside Amplify Hosting (prompts for the value)
aws amplifygen3 var set <SECRET_NAME> --secret --env production
```

To store keys from the file as secrets, add `--secrets` with a comma-separated list of key names. `--secrets ""` stores none, which CI requires because it can’t prompt. List only keys that are in the file: `var upload` fails if a key you name isn’t in the file.

```bash
aws amplifygen3 var upload .env.amplify-hosting --secrets API_KEY,STRIPE_SECRET_KEY --env production
```
+ Variables already in the environment that aren’t in the file are kept, and a variable in the file replaces one with the same name.
+  `var upload` and `var set` target `preview` unless you pass `--env`.
+ If a branch has no overrides, its file is empty and `var upload` stops with `No variables found`. Skip that file.
+ Secret values are stored as SecureString parameters and never appear in CLI output or downloads.

Delete the exported files when you’re done. They contain your secret values. You can also upload a file in the console: under **Environment variables**, choose **Add**, **Upload .env**.

### Update URLs that point at Amplify Hosting
<a name="migrate-step-4-urls"></a>

Variables you copied may still hold your Amplify Hosting URL, for example `NEXTAUTH_URL=https://main.<app-id>.amplifyapp.com`. Find them with `grep -n 'amplifyapp\.com' .env.amplify-hosting*`, or in the console by looking for values that contain `amplifyapp.com`.

After your first production deployment in Step 7, set each of these variables to the production URL that `deploy` prints, including `https://`. Then deploy again:

```bash
aws amplifygen3 var set NEXTAUTH_URL <gen3-production-url> --env production
```

If your app signs in through an OAuth provider, for example GitHub, Auth0, Amazon Cognito, or Clerk, add the Amplify production URL’s callback URL to the provider’s allowed callback URLs. Keep the Amplify Hosting callback until you decommission the Amplify Hosting app. After you transfer your custom domain in Step 9, set these variables to your custom domain.

### Move the SSR compute role
<a name="migrate-step-4-ssr-role"></a>

If your server-side code calls other AWS services through an Amplify Hosting compute role, give each Amplify environment an execution role instead. The role must trust the Amplify service principal, `amplifygen3.amazonaws.com`. Attach this trust policy to the role:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "amplifygen3.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

Give the environment the role. Replace `<account-id>` and `<role-name>`:

```bash
aws amplifygen3 env edit --role-arn arn:aws:iam::<account-id>:role/<role-name> --role-permissions-mode full --env production
```

 `--role-permissions-mode full` lets the environment use the role’s permissions. The new role takes effect at the next deployment.

### Code changes
<a name="migrate-step-4-code"></a>
+  **Amplify Hosting build variables.** `AWS_APP_ID`, `AWS_BRANCH`, `AWS_COMMIT_ID`, `AWS_JOB_ID`, and `AWS_PULL_REQUEST_ID` aren’t set in Amplify. Replace code that reads them.

Done when: `aws amplifygen3 var upload` succeeds for every environment, and your code no longer reads the Amplify Hosting build variables.

## Step 5: Map branches to environments
<a name="migrate-step-5"></a>

In Amplify, environments track branches:


| Amplify Hosting | Amplify | 
| --- | --- | 
| Production branch, for example `main`  |  `production`, tracking `main`  | 
| Long-lived branch, for example `develop`  | A custom environment such as `staging`, tracking `develop`  | 
| Feature branches |  `preview`, tracking a pattern such as `feature/*`  | 
| Pull request previews |  `preview`, with pull request deployments turned on | 
| Pattern-based branch auto-detection | Add the pattern, such as `feature/*`, to one environment’s tracked branches. Every matching branch deploys to that environment. | 

### Map branches using the CLI
<a name="migrate-step-5-cli"></a>

```bash
# production tracks the main branch
aws amplifygen3 app edit --git-branch main
```

 `app edit --git-branch` sets the app’s production branch: production tracks it and preview tracks every other branch. To change which branches any other environment tracks, use `env edit --git-branch` with `--env`.

```bash
# production deploys every push to its tracked branch
aws amplifygen3 env edit --deploy-on-push enable --env production

# staging deploys every push to develop
aws amplifygen3 env create --name staging
aws amplifygen3 var upload .env.amplify-hosting --env staging
aws amplifygen3 env edit --git-branch develop --deploy-on-push enable --env staging

# preview deploys feature branches and builds pull requests from them
aws amplifygen3 env edit --git-branch "feature/*" \
  --deploy-on-push enable --deploy-on-pull-request enable --env preview
```
+  `--git-branch` sets the full list of branches an environment tracks, replacing what was there. To add a branch, repeat the flag with every branch you want, for example `--git-branch "feature/" --git-branch "hotfix/"`.
+ Pull requests build on the environment that tracks their source branch. For example, a pull request from `feature/login` into `main` builds on `preview`, which tracks `feature/*`.
+ An environment that has both `--deploy-on-push` and `--deploy-on-pull-request` enabled deploys each commit on an open pull request twice: once for the push and once for the pull request. To build each commit once, turn off one of them.
+ Pull requests from forks also need `--deploy-on-fork-pull-request enable`, and a maintainer approves each commit with `aws amplifygen3 deployment authorize <commit-hash>`.
+ Several environments can track the same branch. A push deploys to every environment whose pattern matches. The `production` environment can’t use wildcard patterns.
+ Upload each branch’s variable overrides to its environment (Step 4), and turn on access control for new environments (Step 2).
+ To skip a build, put `[skip ci]`, `[ci skip]`, or `[no ci]` in the commit message. The Amplify Hosting `[skip-cd]` isn’t recognized.

### Map branches in the console
<a name="migrate-step-5-console"></a>

1. Choose your app, then **Settings**. In the **Environments** table, choose the environment, then **Edit environment settings**.

1. Under **Branch tracking**, add a rule for each branch, using "is", "is not", "starts with", or "does not start with". Amplify deploys every push to a matching branch to this environment.

1. To build pull requests, select the option to create a preview URL for each pull request.

### Deploy from your own CI
<a name="migrate-step-5-ci"></a>

To deploy from your own pipeline, such as GitHub Actions, run the deploy from that pipeline instead of tracking branches. This also works if your repository isn’t in GitHub or GitLab:

```bash
aws amplifygen3 deploy --env production
```

To build once and deploy the same artifact to several environments, build in CI and run `aws amplifygen3 deploy --prebuilt --env production`.

Done when: each Amplify Hosting branch deploys to its environment, or your CI runs `deploy`.

## Step 6: Move redirects, rewrites, and headers
<a name="migrate-step-6"></a>

Add path redirects and rewrites to `routes` in `amplify.jsonc`. Each key is a path pattern. Each value sets the status code and the destination. In this example, replace `<other-site>` with the site to redirect to:

```json
{
  "routes": {
    "/old-page": { "status": 301, "to": "/new-page" },
    "/blog/*": { "status": 301, "to": "/articles" },
    "/docs": { "status": 302, "to": "https://<other-site>/" },
    "/user/:id": { "status": 200, "to": "/user.html" }
  }
}
```
+  `*` matches any characters, including `/`. `:name` matches one path segment. A pattern matches the whole path, so `/old-page` doesn’t match `/old-page/`.
+  `status` is `301`, `302`, `307`, or `308` for a redirect, or `200` for a rewrite. Without `status`, the rule is a rewrite.
+  `to` is used as written. It can’t include part of the matched path (`*` and `:name` are not substituted), and a redirect doesn’t pass the query string on. A rewrite target must be a path in the app. A redirect target can be a path or an absolute URL.
+ The first matching rule wins. Rules apply before your framework’s own routes.
+ To use different rules in one environment, add `routes` under that environment in `env`. They replace the top-level rules for that environment.
+ Routes are part of each deployment. Deploy again to apply a change.

Map each Amplify Hosting rule:


| Amplify Hosting rule | In Amplify | 
| --- | --- | 
| Root domain to `www` (301), or any hostname to another | A domain redirect, set up in Step 9 after the target domain is active | 
| Path redirect (301, 302, 307, 308) |  `routes`  | 
| Rewrite (200) to another path |  `routes`  | 
| Source with `<*>` or `<placeholder>`  |  `routes` with `*` or `:name`. If the target reuses the matched value, use your framework’s redirects or middleware instead. | 
| Regex source | One or more `routes` patterns, or your framework | 
| Rewrite (200) to an external URL (reverse proxy) | Your framework, for example `rewrites()` in `next.config`. `routes` doesn’t proxy. | 
| 404 rules | Your framework’s not-found page | 
|  `customHttp.yml` or console custom headers | Your framework’s header configuration. In Next.js, use `headers()` in `next.config` or middleware such as `proxy.ts`. Both apply to prerendered pages and static files as well as server-rendered responses. For more information, see [Set response headers](custom-headers.md). | 
| SPA fallback (rewrite unknown paths to `/index.html`, 200) | For a server-rendered app (Next.js, Nuxt, Astro, or SvelteKit), drop the rule. Your framework handles every route, and Amplify Hosting adds this rule to new apps by default. For a single-page app, set `spa_fallback`. See the following section. | 

### Single-page app fallback
<a name="migrate-step-6-spa"></a>

A single-page app that routes in the browser (React Router, Vue Router, and similar) returns `Not Found` when a visitor opens or reloads a deep link such as `/settings`. Set `spa_fallback` at the top level of `amplify.jsonc`, beside `name` and `deploy`:

```json
{
  "name": "<app-name>",
  "deploy": { "install": "npm ci", "build": "npm run build", "output_directory": "dist" },
  "spa_fallback": "/index.html"
}
```
+ Amplify serves `/index.html` with a 200 for any path whose last segment has no `.` and that matches no built file. The URL doesn’t change, so the app sees the route that was opened. This also covers routes you add later.
+ Built files and `routes` match first. A missing file with an extension, such as `/assets/old.js`, still returns 404. A client route with a `.` in its last segment, such as `/users/jane.doe`, also returns 404, so add a `routes` rewrite for it.
+ Don’t use a `"/*"` route for this. It also answers your scripts and styles with the HTML page, and the app loads blank.
+ If you later run `aws amplifygen3 local init` or `local backend add`, they rewrite `amplify.jsonc` and drop `spa_fallback`. Add it back after them.

Amplify returns `404 Not Found` for any other path that isn’t a file, even if your build includes a `404.html`.

### Cookies and the cache
<a name="migrate-step-6-cookies"></a>

Like the Amplify Hosting default cache setting (`AMPLIFY_MANAGED_NO_COOKIES`), Amplify leaves cookies out of the cache key by default. A response your app marks as cacheable is served to every visitor, whatever cookies they send. To keep a response out of the shared cache, send `Cache-Control: private` or `no-store`.

If your Amplify Hosting app uses `AMPLIFY_MANAGED`, which includes cookies in the cache key, set `cache_key` in `amplify.jsonc` to key the cache on every cookie:

```jsonc
{
  "name": "<app-name>",
  "cache_key": {
    "cookies": { "include": ["*"] }
  }
}
```

Amplify doesn’t support the `Vary: Cookie` header, and you can’t key the cache on individual cookies for now. Keying on every cookie lowers your cache hit rate, because visitors with different cookies get separate copies. For more information, see [Cookies and the cache key](caching.md#caching-cookies).

Done when: every rule you collected is in `routes`, `spa_fallback`, or your framework config, and you have deployed.

## Step 7: Deploy and test
<a name="migrate-step-7"></a>

If the repository is connected, pushing to a tracked branch deploys it. To deploy from your machine:

```bash
aws amplifygen3 deploy --logs                   # preview
aws amplifygen3 deploy --env production --logs  # production
```

 `deploy` waits for the build and prints the environment URL. It uploads the files in your current folder, whichever environment you deploy to. It doesn’t build the branch the environment tracks, so check out that branch first. If the folder has no `amplify.jsonc`, `deploy` writes one. Commit it.

In the console, choose your app, then **Deployments**, **New deployment**. Choose your source code, then choose **Deploy**.

Test on the Amplify production URL before you transfer your custom domain:


| Check | How | 
| --- | --- | 
| Pages and routes render | Browse the site, or run your end-to-end tests against the Amplify URL | 
| API routes and server-side rendering work | Call each API route | 
| Rules from Step 6 |  `curl -I <gen3-url>/<path>` for each rule | 
| Variables and secrets are read | Exercise the code that uses them | 
| Images load | Check optimized and static images | 
| Logs are clean |  `aws amplifygen3 logs get --log-type build -d <deployment-id>`, then `aws amplifygen3 logs get --env production`  | 
| Protected environments ask visitors to sign in | Open the preview URL in a private browser window | 

Done when: every check in the table passes on the Amplify production URL.

## Step 8: Set up monitoring
<a name="migrate-step-8"></a>

Set up monitoring on the Amplify app before the domain transfer, so you can watch it during and after the transfer. Alarms on `AWS/AmplifyHosting` metrics stop receiving data once traffic moves.


| Amplify Hosting | Amplify | 
| --- | --- | 
| CloudWatch metrics in `AWS/AmplifyHosting`: Requests, BytesDownloaded, BytesUploaded, 4xxErrors, 5xxErrors, Latency | CloudWatch metrics in `AWS/AmplifyGen3` in your account, with dimensions `AppName` and `EnvironmentName`: `WebRequests`, `Web4xxErrors`, `Web5xxErrors`, `WebDataTransferOut`, `WebLatency`, and `WebCacheHitRate`. Server-side rendering and middleware add `ComputeInvocations`, `ComputeDuration`, `ComputeMaxMemoryUsed`, and `ComputeCpuTime`, with a `ComputeType` dimension that separates the two. The firewall adds `WafTotalRequests`, `WafAllowedRequests`, and `WafBlockedRequests`. | 
| Access logs downloaded from the console |  `aws amplifygen3 logs get --log-type access`  | 
| Build logs in the console |  **Deployments** in the console, or `aws amplifygen3 logs get --log-type build -d <deployment-id>`  | 
| SSR logs in CloudWatch Logs |  `aws amplifygen3 logs get` (runtime logs) | 
| CloudWatch alarms | New alarms on the Amplify metrics | 

In `production`, Amplify delivers 5% of requests to CloudWatch Logs from the start. Other environments deliver no access logs until you set a sampling rate. To check the log configuration, and to capture every request with a sampling rate of 100, run:

```bash
aws amplifygen3 logs-config get --env production
aws amplifygen3 logs-config edit --access-log-cwl-sampling-rate 100 --env production
```

Done when: you have CloudWatch alarms on the Amplify metrics.

## Step 9: Transfer your custom domain
<a name="migrate-step-9"></a>

Your site is unavailable on the custom domain while you transfer it. This is the only step with downtime. For the steps, including how to roll back and how to decommission the Amplify Hosting app, see [Transfer your custom domain from Amplify Hosting](migrate-custom-domain.md).

## Troubleshooting
<a name="migrate-troubleshooting"></a>

For domain problems, see [Transfer your custom domain from Amplify Hosting](migrate-custom-domain.md).

### The first deploy fails because the output directory doesn’t exist
<a name="migrate-ts-output-dir"></a>

The build didn’t produce the output directory. Check that `deploy.build` and `deploy.output_directory` in `amplify.jsonc` are the values `aws amplifygen3 create` wrote for your framework. Then run the same build command locally, and confirm the folder appears.

### A variable is missing at run time
<a name="migrate-ts-missing-var"></a>

Variables apply from the next deployment, so redeploy after you add them. Check that you set them on the right environment: commands target `preview` unless you pass `--env`.

### The build takes longer than an hour
<a name="migrate-ts-build-time"></a>

Request a quota increase, or build in CI and deploy the output with `aws amplifygen3 deploy --prebuilt`.