View a markdown version of this page

Pull requests for your Amplify app - AWS Amplify

Pull requests for your Amplify app

Welcome to the new AWS Amplify

Amplify now puts hosting, a Postgres database, and sign-in in one AWS account. Deploy from your terminal or from Git, check every change in a preview first, and roll back in one step if something breaks.

Looking for Amplify Hosting? See the Amplify Hosting User Guide.

Pull request previews

If your app code is stored in GitHub or GitLab, Amplify supports advanced pull request settings. If someone opens a pull request on your repository, Amplify will automatically trigger a deployment to the preview environment. Amplify will then post a comment on the pull request with the deployment details and a link to the Amplify console. As the deployment status changes, Amplify will update that comment.

Finally, when the deployment completes, Amplify adds the pull request’s own preview URL to the pull request. You can also see the deployment status described as "GitHub Checks". If the pull request is updated with new commits, the process will repeat.

An environment deploys a pull request from your repository when it tracks the pull request’s source branch and has --deploy-on-pull-request enabled. When you connect a repository, the preview environment has both. For the settings, see Choose the events that start a deployment.

Fork pull-request deployments

To control unauthorized deployments, Amplify doesn’t build and deploy pull requests from a fork repository automatically. A fork can carry untrusted code. You can deploy a pull request from a fork to an environment only when you enable both --deploy-on-pull-request and --deploy-on-fork-pull-request on that environment. When you connect a repository, Amplify enables both on the preview environment of an app without a backend. An app with a backend never deploys pull requests from forks. To turn fork pull-request deployments on for another environment, run the following command. Replace staging with the name of your environment.

aws amplifygen3 env edit --env staging --deploy-on-pull-request enable --deploy-on-fork-pull-request enable

Even then, a fork pull request stays pending until you authorize the exact commit. Authorization applies per commit, so when new commits are pushed to the pull request, you must authorize each new commit again. Before you authorize a commit, review its changes. For the risks, see Set up continuous deployment from Git.

You can complete the authorization in the Amplify console, or authorize a specific commit using the following CLI command. Pass the full 40-character hash of the pull request’s latest commit. The command defaults to the preview environment. Use --env to target a different environment.

aws amplifygen3 deployment authorize <commit-hash> --env preview

The output looks like the following:

✓ Authorized commit 3f2a9c1 for deployment to environment 'preview'. The preview build starts now. Track it: aws amplifygen3 deployment list -e preview Note: This covers this commit only. A new push to the pull request needs authorizing again.

You can safely authorize the same commit again. Doing so doesn’t start a new deployment. A pull request that waits for authorization doesn’t appear in aws amplifygen3 deployment list until you authorize it.

Remove a preview URL

When a pull request is closed or merged, its preview URL stops serving. To remove the branch and pull request preview URLs of a deployment yourself, run the following command:

aws amplifygen3 deployment disable --id <deployment-id> --env preview

The output looks like the following:

✓ Removed the preview URLs of deployment 'a1b2c3d4e5' in environment 'preview'. The deployment remains in history, and its own URL is not affected.

The output then lists each URL that it removed. The command doesn’t delete the deployment, and the deployment’s own URL keeps working. You can’t disable the deployment that serves the environment URL. To move the environment to another deployment first, use aws amplifygen3 deployment promote or aws amplifygen3 rollback.