

# Create an instant rollback

An instant rollback moves an environment URL, with no rebuild, to the newest successful deployment that was created before the one it serves now. Use it when something is wrong and you need the fastest path back to the last known-good deployment. The change reaches all viewers in about 5 to 10 seconds. Until then, some requests still get the deployment that you rolled back from.

When you roll back, Amplify updates any custom domain that you mapped to the environment.

The deployment you roll back from stays in history, so you can re-promote it once you understand the issue. For instructions on re-promoting a deployment, see [Promote a deployment in the console](deploy-your-app-promote.html#deploy-your-app-promote-console).

AWS CloudTrail records each rollback, including who made it and when. For more information about finding logs, see [Which log should I look in?](monitoring-overview.html#monitoring-which-log) in *Monitoring AWS Amplify*.

An instant rollback skips any deployment created after the one it serves now, and you don’t specify a deployment ID. To return to a specific deployment, promote it, as described in the section on rolling back to a specific deployment later on this page.

**Rollbacks don’t undo migrations**  
If your app has a backend, a rollback changes only which deployment serves traffic. It doesn’t undo migrations, so your database keeps the schema from the newest deployment that ran them. Test each schema change in a `preview` environment first.  
A deployment applies migrations before it builds the site, so a deployment whose build failed also leaves its schema changes in place. To undo a schema change, deploy a new migration that reverses it. A rollback also brings back the publishable key that the older deployment was built with. If you revoked that key since, your app’s backend requests get `401` `invalid_credential` until you deploy again. To recover production data as of an earlier time, see [Backups and restore](backend-backups.md).

## Create an instant rollback in the console
<a name="_create_an_instant_rollback_in_the_console"></a>

1. Sign in to the Amplify console at [https://us-east-2.console.aws.amazon.com/amplifygen3/home](https://us-east-2.console.aws.amazon.com/amplifygen3/home).

1. Choose an app.

1. In the left navigation pane, choose **Deployments**.

1. Choose the active deployment.

1. For **Actions**, choose **Rollback**.

Traffic shifts back to the previous stable deployment in about 5 to 10 seconds.

## Create an instant rollback using the CLI
<a name="_create_an_instant_rollback_using_the_cli"></a>

The following CLI command reverts the production environment to its previous stable deployment. You do not need to specify a deployment ID.

```bash
aws amplifygen3 rollback --env production
```

If you omit `--env`, the command rolls back the `preview` environment. The command returns an error when there is no previous deployment to roll back to.

## Roll back to a specific deployment
<a name="_roll_back_to_a_specific_deployment"></a>

To revert to an older deployment rather than the immediately previous one, list the deployments for the environment, and then promote the one you want. When you promote a deployment, Amplify does not rebuild your app.

```bash
aws amplifygen3 deployment list --env production
aws amplifygen3 deployment promote --id a1b2c3d4e5 --env production
```

For more information, see [Promote a deployment](deploy-your-app-promote.md).

## Roll back during a gradual rollout
<a name="_roll_back_during_a_gradual_rollout"></a>

While a gradual rollout is in progress on the environment, `aws amplifygen3 rollback` fails with exit code 251. To stop the rollout and send all traffic back to the previous deployment, run `aws amplifygen3 deployment abort --env <environment>` instead. For more information about rollouts, see [Gradual deployments](deploy-your-app-gradual-deployments.md).

## Limits
<a name="_limits"></a>

Amplify retains the last 50 successful deployments for each environment. An expired deployment can’t be the target of an instant rollback. To restore the version of an expired deployment, create a new deployment. For more information, see [Create a new deployment](deploy-your-app-deployments.md).

## Confirm which deployment is serving traffic
<a name="_confirm_which_deployment_is_serving_traffic"></a>

After a rollback, you can check which deployment is active for your environment. For more information, see [Determine which deployment is serving traffic](deploy-your-app-serving-traffic.md).