Search code examples
amazon-web-servicesaws-amplify

AWS Auth parameters are overwritten in multiple env


I have different callback urls for each environment and if I use amplify auth update and fix the URL it still gets overwritten in amplify/backend/auth/projectname/parameters.json if I merge master into my dev branch and its quite frustrating. Not sure what the solution is.


Solution

  • As of now, Amplify doesn't have any support for environment specific for parameters.json.

    What worked for our team is we overwrite our parameters.json in our CI/CD pipeline (we only have different parameters for production environment)

    so, we made a script (in node). This is an example of our custom config.

    Our solution depends on the amplify environment name. Currently, we use prod prefix for our production environments. So, you'll see something like process.env.USER_BRANCH.startsWith('prod')

    config.json

    module.exports = {
        'api': {
            filePath: 'amplify/backend/api/myproject/parameters.json',
            override: {
                production: {
                    ElasticSearchInstanceCount: 3,
                    ElasticSearchInstanceType: 't2.medium.elasticsearch'
                }
            }
        }
    }
    

    script.js (not a complete version)

    if(!process.env.USER_BRANCH || !process.env.USER_BRANCH.startsWith('prod')) return
    const parameter = JSON.parse(fs.readFileSync(config.filePath))
    const overrideConfig = config.override['production']
    fs.writeFileSync(config.filePath, JSON.stringify({
       ...parameter,
       ...overrideConfig
    }))
    

    and lastly, in your amplify.yml, run node ./script.js before amplifyPush. e.g.

    version: 0.1
    backend:
      phases:
        build:
          commands:
            - node ./scripts/src/amplify-parameters-override/script.js
            - amplifyPush --simple