Local development workflow
Develop on your computer first, and deploy when the change works. You apply a migration on the local backend, try it in your app and reset the data as often as you need, with no deployment in between. Deploy to preview when you want to share the change or try it in AWS.
Start in one of the following ways, and then follow the daily loop:
-
Start a new app – You’re adding a backend to an app on your computer.
-
Work on an existing app – You cloned an app that already has a backend.
Before you begin
You need the following:
-
Docker or Finch, running. Docker is the default. For more information about Finch, see Docker and Finch.
-
Node.js and your package manager, for your app’s dev server.
-
A network connection the first time you run
aws amplifygen3 local run, to download the local backend image.local init --type fullstackalso needs one in a folder that has apackage.json, to install the client SDK packages. To skip the install, add--skip-install.
Run each local command from your app’s folder, the one that holds amplify.jsonc. The local commands need no AWS credentials. You need AWS credentials to deploy.
Start a new app
Follow these steps to add a backend to a new app:
-
Create your app with its framework’s tool, such as
create-next-app. -
Run the following command in the app’s folder to add a backend:
aws amplifygen3 local init --type fullstackThe command writes
amplify.jsoncwith abackendblock, and createsmigrations/,.secrets/andamplify.local.json. If your app has apackage.json, it also adds the Amplify backend client packages. For an app that already has anamplify.jsoncfile, runaws amplifygen3 local backend addinstead. -
Install your app’s dependencies, such as with
npm install. -
Run the following command to start the local backend and your app’s dev server:
aws amplifygen3 local runThe command starts the backend, applies your migrations, and starts the dev server in the foreground. You should see the backend URL, the local publishable key
hpk_v1.local, and the addresses of the local console and Mailpit.local runpassesAMPLIFY_BACKEND_URLandAMPLIFY_BACKEND_PUBLISHABLE_KEYto the dev server. AWS Amplify sets the same variables in every deployment. A dev server that you start another way gets neither variable.
Pass --type fullstack each time you run local init in a project with a backend. Without it, the command comments out the backend block. local init and local backend add rewrite amplify.jsonc with only name, env, deploy, and backend. They drop your comments and every other top-level key, such as routes, cache_key, and spa_fallback, without a warning, so save a copy of the file first. With --force, the command rewrites amplify.jsonc and amplify.local.json, and you lose your edits to both, including backend.auth. The app name resets to the --app value or the folder name.
To stop only the dev server, press Ctrl+C in the local run terminal. The backend keeps running. To stop the backend and the dev server, run aws amplifygen3 local stop from any terminal.
Work on an existing app
After you clone an app that already has a backend, install its dependencies, and run aws amplifygen3 local run. The command creates a local backend for your copy and applies the migrations. To load the sample data in seed.sql, run aws amplifygen3 local backend seed.
Each copy of your project folder, such as a clone or a Git worktree, has its own local backend.
What to commit
The following table shows which project files to commit:
| File or folder | Commit it | What it holds |
|---|---|---|
|
|
Yes |
Your app’s settings, including the |
|
|
Yes |
Your schema, as SQL migration files |
|
|
Yes, if you use one |
Sample data for the local backend |
|
|
No |
This computer’s local backend name, ports and addresses |
|
|
No |
The local database password and your client secrets |
local init adds amplify.local.json and .secrets/ to .gitignore.
The daily loop
The following steps add a table on the local backend and deploy it to preview:
-
Run the following command to create a migration file, and then write the table, its grants and its row-level security (RLS) policies in it:
aws amplifygen3 local migration create --description "create notes" -
Run the following command to apply the migration to the local backend:
aws amplifygen3 local migration applyRun
aws amplifygen3 local migration listto check that no migration is pending. -
Try the change in your app, and test your RLS policies as a signed-in user and as a visitor. For more information, see Local database.
-
Commit
amplify.jsoncandmigrations/. -
Run the following command to deploy to
preview:aws amplifygen3 deployThe deployment applies the new migrations to the
previewenvironment. After you checkpreview, deploy toproductionwithaws amplifygen3 deploy -e production.
For more information about migrations and RLS policies, see Tables and migrations.
After you pull new migrations with Git, local run applies them as it starts. After you change amplify.jsonc, .secrets/client_secrets.env, or a file in email-templates/, press Ctrl+C in the local run terminal, and then run aws amplifygen3 local run again. local run restarts the backend with the new settings and keeps your data. If the backend can’t start with the new settings, it keeps running with the previous ones.
Stop the first local run before you start it again. If the first dev server still holds its port, a second local run starts the dev server on the next port. Next.js 16 refuses a second dev server in the same folder.
When you switch Git branches in one folder, the local backend keeps the same database. To keep separate local data for each Git branch, use one Git worktree for each branch.
Commands at a glance
The local commands act on the local backend. Each task has a deployed command too. The deployed commands sign with your AWS credentials and take --env to name the environment.
| Task | Local backend | Deployed environment |
|---|---|---|
|
Run SQL, dump, lint and inspect |
|
|
|
Apply migrations |
|
|
|
List applied migrations |
|
|
|
Manage users |
|
|
|
Load seed data |
|
|
|
Generate TypeScript types |
|
|
|
Read logs |
|
|
The db and backend user commands act on preview when you leave out --env. Local users are separate from the users in every environment.
Check the local backend
Run the following command to see the state of each service, the backend URL and the local console address:
aws amplifygen3 local status
The status of each service is healthy, disabled, unhealthy or unreachable. To print only the backend URL, such as for a script, add --output text --query data.endpoint.
Run the following command to read the backend’s output:
aws amplifygen3 local logs --tail 200
Add --follow to stream the output, --log-type database for the PostgreSQL logs, or --log-type backend-access for the request logs. To find one request, add --request-id with the value of the response’s x-request-id header. The --request-id option requires --log-type backend-access.
Stop and clean up
Run the following command from any terminal to stop the backend and the dev server that local run started:
aws amplifygen3 local stop
Your local data stays, and the next local run starts with it.
To delete the local backend and its data, run the following command:
aws amplifygen3 local destroy
On a terminal, the command lists what it deletes and asks you to confirm. In a script, it prints the list and exits with status 2, and it deletes nothing. To delete without the prompt, add --yes.
local destroy deletes all local data: your tables, rows and local users, and the emails in Mailpit. It keeps your project files, such as migrations/, .secrets/ and amplify.local.json.
To keep your schema and delete only the data, reset the local database. For more information, see Local database.
Before you delete a copy of your project folder, run aws amplifygen3 local destroy in it. Otherwise its containers and data stay in Docker or Finch.
Use the local commands in scripts
When the output isn’t a terminal, the local commands print JSON. On a terminal, add --output json to get the same JSON. A result has "ok": true and a data object on standard output. An error has "ok": false and an error object with kind, message and resolution on standard error. --query filters the result, starting at data, such as --query data.endpoint.
The commands exit with the following status:
| Exit status | Meaning |
|---|---|
|
|
The command succeeded. |
|
|
The command failed. Read |
|
|
The command needs confirmation, and it changed nothing. |
|
|
An argument is wrong, such as an unknown flag. |
local run exits with the dev server’s exit code when the dev server stops with an error.
local run options
local run takes the following options:
| Option | What it does |
|---|---|
|
|
The backend URL’s port. The default is |
|
|
The PostgreSQL port. The default is |
|
|
The local console’s port. The default is |
|
|
The port of Mailpit’s web UI and API. The default is |
|
|
Downloads the current local backend image again, and recreates the backend from it. |
|
|
Starts the backend without applying pending migrations. |
local run reuses the same ports on later runs while they’re free. When you set a port with an option, local run always uses that port, and it fails if another program uses the port. Every port listens only on your computer.
Errors
The local commands return the following errors:
kind
|
Cause | What to do |
|---|---|---|
|
|
The folder has no |
Run the command from your app’s folder. In a new project, run |
|
|
The local backend isn’t running. |
Run |
|
|
Docker or Finch isn’t installed or isn’t running. |
Start Docker or Finch, and run the command again. For more information, see Docker and Finch. |
|
|
A port that you set with an option is busy, or the dev server’s port is one that the backend uses. |
Leave out the option, set another port, or change the dev server’s port. |
|
|
A port option names another port than the running backend uses. Nothing changed. |
To move the backend, run |
|
|
A migration failed as |
Fix the file, and run |
|
|
The backend couldn’t start with the changed |
Fix what the message quotes, and run |
|
|
The backend stopped while it was starting. The message quotes the first error. |
Fix what the message names, and run |