AWS Amplify, set yml commands for a specific environment

Viewed 778

My app has two environments: develop and production. Each environment has different npm commands to build a specific configuration.

my amplify.yml looks like this:

version: 1
frontend:
   phases:
       preBuild:
           commands: ['npm ci']
       build:
           commands: ['npm run build']
   artifacts:
       baseDirectory: dist/my-app
       files:
           - '**/*'
   cache:
       paths:
           - 'node_modules/**/*'

I need the build command to be different for production but I don't see a way to specify environment with the amplify.yml file

2 Answers

Here you have the documentation for conditional build

build:
  commands:
    - if [ $AWS_BRANCH == 'main' ] ; then npm run build:prod; fi
    - if [ $AWS_BRANCH == 'dev' ] ; then npm run build:dev; fi
Related