Docker and Finch
aws amplifygen3 local run runs your local AWS Amplify backend in containers on your computer, with Docker or Finch. Docker is the default. To use Finch, set the containerRuntime key in amplify.local.json or the AWS_AMPLIFY_CONTAINER_RUNTIME environment variable.
Which runtime to choose
Use Docker when Docker Desktop is installed or you can install it. For more information about installing Docker, see Get Docker
Use Finch when Docker Desktop isn’t an option on your computer. Your teammates can use Docker with the same project.
Requirements
To run the local backend, you need the following:
-
A running runtime – Start Docker, or start Finch with
finch vm start, before you runaws amplifygen3 local runand the otherlocalcommands that use the local backend.aws amplifygen3 local initandaws amplifygen3 local backend addonly write files, and they don’t use the runtime. -
A network connection for the first
local run– The command downloads the local backend image from Amazon ECR Public, without signing in. Later runs work offline for up to 7 days after the CLI last verified the image. -
Finch on Linux – Finch runs as root. The
finchcommand on yourPATHmust runsudo -E finch. A plainsudodrops the environment variables that the CLI passes to the containers, and the local backend stops as it starts.
Local backends that run at the same time share one Docker or Finch engine. When the engine is busy, every local command runs slower. To free the engine, run aws amplifygen3 local stop in each project that you aren’t using.
How the CLI picks a runtime
You choose the runtime with the AWS_AMPLIFY_CONTAINER_RUNTIME environment variable or the containerRuntime key in amplify.local.json. Each takes docker or finch.
When both are set, AWS_AMPLIFY_CONTAINER_RUNTIME takes precedence over containerRuntime.
aws amplifygen3 local run checks the runtime in two steps before it starts the local backend:
-
The
dockerorfinchcommand is on yourPATH. -
The runtime’s
infocommand succeeds. It fails when the Docker daemon or the Finch virtual machine is stopped.
If either check fails, the command stops with container_runtime_not_found. Install the runtime, or start it (finch vm start for Finch), and run the command again. The CLI doesn’t switch runtimes on its own. When the other runtime’s command is on your PATH, the error’s resolution names that runtime and the setting to switch to it.
Switch to Finch
To use Finch for every command in a project, add "containerRuntime": "finch" to amplify.local.json in the project folder. The file isn’t committed, so your teammates keep their own runtime.
To use Finch for one command, set AWS_AMPLIFY_CONTAINER_RUNTIME on the command line. Run the following commands to start Finch and the local backend:
finch vm start AWS_AMPLIFY_CONTAINER_RUNTIME=finch aws amplifygen3 local run
To go back to Docker, set the value to docker, or remove the key and the variable.
Docker and Finch keep separate containers and volumes. When you switch runtimes, local run starts a new local backend with an empty database and applies your migrations. The old backend and its data stay in the runtime that created them. To remove them, switch back to that runtime and run aws amplifygen3 local destroy.
The PostgreSQL client for the db commands
The aws amplifygen3 local db commands run psql inside the running local backend. You don’t install a client for them. For more information about these commands, see Local database.
The following commands work on a deployed environment and run psql: db query, db connect, db lint, db inspect, db report, backend seed and backend gen-types. db dump runs pg_dump. While Docker or Finch runs, each of these commands runs the client in a container from the local backend image. If the image isn’t on your computer, the command downloads it first and prints Pulling the local backend image…. The first download is large. Later downloads reuse its layers.
Read files through standard input
The psql in the image can’t read or write files on your computer. db query and backend seed stop with exit status 252 when the SQL has a psql command that names a file, such as \copy to or from a file, \i, \ir, \w, or \o and \g with a file name. Pipe the file in instead. Run the following command to load a CSV file into a table:
aws amplifygen3 db query "\copy notes from stdin csv" --env preview < notes.csv
Replace notes with the name of your table and notes.csv with your file. To run the file commands as written, name your own psql with --psql.
Use your own client
On a computer without Docker or Finch, install a client and name it on each command. Without a runtime or a named client, these commands stop with Docker is not running or not installed. The deployed database commands run psql in a container. (exit status 253). db dump needs pg_dump 17 or later, and the other commands need psql 16 or later. PostgreSQL 17 or later has both. The CLI uses a client that you name even while Docker runs. It doesn’t use a psql that is only on your PATH.
Install the client with one of the following commands:
| System | Install command | Path to name |
|---|---|---|
|
macOS |
|
|
|
Amazon Linux 2023 |
|
The |
|
Debian or Ubuntu |
|
The |
Run the following command to name the client on one command:
aws amplifygen3 db query "select now()" --env preview --psql "$(brew --prefix libpq)/bin/psql"
For db dump, name pg_dump with --pg-dump. To name a client once for every command, set AWS_AMPLIFY_PSQL_BIN and AWS_AMPLIFY_PG_DUMP_BIN to the paths of psql and pg_dump.
Settings
| Setting | Where | Values |
|---|---|---|
|
|
Environment variable |
|
|
|
|
|
|
|
Flag on a |
Path to |
|
|
Flag on |
Path to |
Errors
| Error | Cause | Fix |
|---|---|---|
|
|
The runtime’s command isn’t on your |
Install Docker or Finch, then run the command again |
|
|
The runtime’s |
Start Docker, or run |
|
|
|
Set it to |
|
|
A |
Start Docker or Finch, or name a client with |
|
|
The client that you named is too old |
Name |
|
Exit status 252 from |
The SQL has a |
Pipe the file through standard input, or name your own |
|
|
The runtime couldn’t create the local backend’s network. The message quotes the runtime’s error |
Fix what the message names, then run |
|
The local backend stops as it starts, on Linux with Finch |
The |
Make it run |