View a markdown version of this page

Create a new deployment - AWS Amplify

Create a new deployment

You can create a new deployment at any time using the Amplify console or CLI. You can’t update a deployment. To make a change to your app, create a new deployment. If you want to completely delete a deployment URL, delete your app. For more information, see Delete your app.

What is a deployment?

A deployment is a snapshot of your app released to an environment. The code in your app is based on the source code you specify. The environment is based on which environment you select. If you create an environment variable, that is released with the deployment. The endpoint is available on the public internet. You receive a deployment URL that you can share.

You can view each deployment and the deployment details. These details are the environment variables, source code, and any integrations. If you created a secret environment variable, you will not be able to see it in the console.

Creating an app with aws amplifygen3 create doesn’t deploy it. Your first aws amplifygen3 deploy, or your first push to a connected Git branch, creates the app’s first deployment. To make other changes, you must redeploy your app.

Deployments to one environment from the same source run one at a time. All uploads from aws amplifygen3 deploy count as one source, and each Git branch is another. When several deployments from one source are waiting, only the newest one runs, and the older ones end as CANCELLED.

Deployment retention

Amplify retains the last 50 successful deployments per environment. This retention window defines which deployments are available for you to promote to your environment. For more information, see Promote a deployment.

When a new deployment succeeds and the environment exceeds this limit, the oldest deployments are automatically expired, unless they are currently serving traffic via an alias.

Expired deployments:

  • Cannot be targeted for instant rollback. To restore that version, create a new deployment.

  • Remain visible in the deployment list with an EXPIRED status.

  • Have their compute endpoint deleted when they expire.

Deployments for an app with a backend

If your app has a backend, each deployment also updates the backend branch that it deploys to. For more information about which branch each environment, Git branch, and pull request uses, see Use environments for your apps.

A deployment changes the backend in the following order:

  1. It waits, with the status Queued, until the branch’s database is ready. The first deployment to a new branch creates its database. If the database isn’t ready within 15 minutes, the deployment fails with INTERNAL_SERVICE_ERROR.

  2. It applies the migrations in your migrations/ folder that the branch doesn’t have yet, in file name order. Each file runs in its own transaction. The deployment fails if a file name doesn’t follow the naming rule, a new file sorts before one that the branch already applied, or an applied file has changed or is missing. For the rules, see Tables and migrations.

  3. It builds and deploys your site.

With your migrations, each deployment sends the backend settings of its environment to the branch, such as the sign-in settings in amplify.jsonc. For where a deployment takes those settings from, see Use environments for your apps.

If a migration fails, the deployment stops with MIGRATION_FAILED, and your site keeps serving the previous deployment. The failed file’s changes are discarded, because each file runs in its own transaction, and the files after it don’t run. Files that ran before it stay applied. Fix that file and deploy again. aws amplifygen3 deployment get --id <deployment-id> shows the file, the PostgreSQL error, its SQLSTATE code, and the line when PostgreSQL reports one.

Migrations that were applied stay applied, even if the build that follows them fails or you roll back the website later. So test each schema change in preview before you deploy it to production. For more information about writing migrations, see Tables and migrations.

Only the CLI creates a backend. aws amplifygen3 create or aws amplifygen3 deploy creates it when amplify.jsonc has a backend block, and so does aws amplifygen3 app edit --backend add. A deployment from a Git push doesn’t create a backend. For more information, see Add or remove a backend.

If the backend is paused or being deleted, aws amplifygen3 deploy stops before it uploads anything, with Deployment failed. Backend status: PAUSED or DELETING. For a paused backend, run aws amplifygen3 backend resume, wait until aws amplifygen3 app get shows the backend as READY, and then deploy again. For when a backend pauses and when a resume is refused, see Capacity.

Create a deployment using the console

To create a new deployment:

  1. Sign in to the Amplify console.

  2. Choose an app.

  3. In the left navigation pane, choose Deployments.

  4. For Deployments, choose New deployment.

  5. Choose your source code. To deploy your code from a different source, such as to change your source code from a GitHub repository to a local file, see Update your app.

  6. Choose Deploy.

Amplify will deploy your code to the deployment URL for you. It takes 5 to 10 minutes for the deployment to complete.

If you want to change the environment variables, you do this in the Settings section. For more information, see environment variables.

Create a deployment using the CLI

To deploy using a terminal, you need AWS credentials. You can use aws login or your AWS credentials file. An amplify.jsonc file is optional, and you don’t need to build your app first, though a local build is a good check. Amplify runs the deploy.install and deploy.build commands on its build service. For what the command uploads, see What the deploy command packages and prints.

Use the following command to deploy your app:

aws amplifygen3 deploy

The command deploys to the preview environment. To deploy to another environment, add --env, for example aws amplifygen3 deploy --env production.

This command does the following:

  • Packages your app’s folder and uploads it to Amplify

  • Prints the deployment ID and the environment’s URL on the Visit: line

  • Runs the deploy.install and deploy.build commands from amplify.jsonc on the Amplify build service

  • Deploys the build to the environment

The output will look like the following:

Deploying to App "my-app" → Uploading files ✓ Files uploaded in 5.0s DeploymentID a1b2c3d4e5 created in Environment preview! Visit: https://preview-ab12--my-app.amplify.app Monitor: https://us-east-1.console.aws.amazon.com/amplifygen3/apps/my-app/deployments/preview/a1b2c3d4e5 → Queued... → In progress... ✓ Migrations applied in 22s (0 applied, 1 skipped) ✓ Built in 1.7s ✓ Deployed in 12s ✓ Deployment succeeded! (38s) ✓ Backend READY on branch source-upload: no new migrations, 1 already applied; /health answers 200 ✓ https://preview-ab12--my-app.amplify.app answers 200 after 2s

What the deploy command packages and prints

Without amplify.jsonc, aws amplifygen3 deploy takes the app name from package.json or the folder name and asks you to confirm it. In a CI session, where nobody can answer, add --app or --yes.

The command packages the current folder as it is on disk, including changes that you haven’t committed. It leaves out .git, node_modules, the build output folder that deploy.output_directory names unless it’s named public, and the paths that your .gitignore and .amplifyignore files exclude. A ! pattern in .amplifyignore can bring back a path that .gitignore excludes. For an app with a backend, it always includes the email-templates/ folder beside amplify.jsonc.

As each step finishes, the command prints a line with the time that the step took. The Deployment succeeded! line gives the time that the deployment ran, which leaves out the time that it waited Queued. For a first backend deployment, that wait can be the largest part. A symbolic link to a file outside your app’s folder is left out with a warning, unless you add --follow-symlinks, which publishes that file at the deployment URL.

The command waits for the deployment to finish, for up to 30 minutes, and exits with an error if the deployment fails. To return as soon as the deployment is created, add --no-wait. The command then prints the aws amplifygen3 deployment get --watch command that waits for the result. To stream the build output while you wait, add --logs.

For an app with a backend, the output also has a Migrations applied line before Built, with the time and the number of files applied. After the deployment, the command reports whether the backend is READY and which migrations the deployment applied. With --logs, the command prints the DeploymentID, Visit: and Monitor: lines again after Deployment succeeded!. After every successful deployment, it checks, for up to a minute, that the URL answers. A new URL can take up to a minute to reach every edge location, so a visitor in that first minute can see an error.

If the deployment fails, the command prints its deployment ID, if one was created, and the request ID when a call to the service failed. When the call failed before a deployment existed, it prints No deployment was created. with the request ID. A failed deployment from your folder also prints the aws amplifygen3 logs get command for its full build log. To see a deployment’s status and details later, run aws amplifygen3 deployment get --id <deployment-id>.