How can I configure Amplify to create a new backend environment for each branch?

Viewed 403

I'm trying to configure Amplify to deploy every branch or PR on my Github repo to a new environment.

Using Previews:

  • Pull Request Previews is enabled
  • The configuration for the backend is "Create new backend environment for every Pull Request"

But every build skips the backend step with this message "No backend environment association found, continuing..." and because of that the frontend build fails because it requires the aws-exports file that should be generated on the backend stage.

The same occurs with Branch autodetection (With the option Create new backend environment for every connected branch selected)

I'm opening this question here because I couldn't get any answer from AWS on their repo

1 Answers

We were recently facing the same issue and discovered that in order to be able to automatically create new BE environments for Previews or Branch autodetection, you need to add backend build step into Build settings in Amplify (amplify.yml).

It can be found in Amplify documentation and in the most simple form it should look like this:

backend:
  phases:
    build:
      commands:
        - amplifyPush --simple

It is not very well documented or obvious, we stumbled across the solution by chance.

Related