Skip to content

Instantly share code, notes, and snippets.

@fortejas
Last active February 25, 2021 16:07
Show Gist options
  • Save fortejas/72cfca2d7a7ff085a30a23572e678944 to your computer and use it in GitHub Desktop.
Save fortejas/72cfca2d7a7ff085a30a23572e678944 to your computer and use it in GitHub Desktop.
Using Secrets per Environment with CoPilot CLI

Using Secrets per Environment with CoPilot CLI

This assumes that we have a CoPilot app called test-app and both a test & prod environment configured.

  1. Start by uploading environment variables for our application's environments

    $ # Test Param
    $ aws ssm put-parameter \
        --name /copilot/apps/test-app/test/dbstring \
        --value 'psql://test:test@testdb.internal' \
        --type SecureString \
        --tags Key=copilot-environment,Value=prod Key=copilot-application,Value=test-app
        
    $ # Prod Param
    $ aws ssm put-parameter \
        --name /copilot/apps/test-app/prod/dbstring \
        --value 'psql://prod:prod@proddb.internal' \
        --type SecureString \
        --tags Key=copilot-environment,Value=prod Key=copilot-application,Value=test-app
  2. Update the manifest.yaml to use environment which overrides per environment

secrets:
  DB_STRING: /copilot/apps/test-app/test/dbstring

environments:
  prod:
    secrets:
      DB_STRING: /copilot/apps/test-app/prod/dbstring

Here the default is to use the test variable but when deploying to prod it specifically uses a production variable.

@chmurson
Copy link

chmurson commented Feb 25, 2021

Thank you! 💟 (Why this is not in docs of Copilot 🙈 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment