I have environment variable secrets I’d like to use
I have a serverless.yml file
I’d like to commit serverless.yml to version control
How do I manage all these desires without committing secrets to git? Is there a better way than just never committing serverless.yml?
Just focusing on the AWS ecosystem:
Is there upcoming functionality to use encrypted environment variables in serverless.yml and have kms decrypt them?
I store my environment variables in the root of my project in a .env file that’s in the .gitignore and I’ll load that into a JS file that can be referenced via serverless.yml
Check the serverless-kms-secrets plugin (https://github.com/SC5/serverless-kms-secrets). It allows you to encrypt variables using KMS.
The module is still at its early phases, some rough edges in the dev experience that need to get polished but gets the job done.
default: &default
<<: *default
COMMON_API_KEY: "AN API KEY COMMON TO ALL ENVIRONMENTS"
COMMON_API_SECRET: "AN API KEY COMMON TO ALL ENVIRONMENTS"
dev:
<<: *default
API_KEY: "YOUR DEVELOPMENT API KEY"
API_SECRET: "YOUR DEVELOPMENT API SECRET"
stage:
<<: *default
API_KEY: "YOUR STAGING API KEY"
API_SECRET: "YOUR STAGING API SECRET"
prod:
<<: *default
API_KEY: "YOUR PRODUCTION API KEY"
API_SECRET: "YOUR PRODUCTION API SECRET"
This might be completely irrelevant, but I found it useful.
If you are using gitlab, you can run your deployments from gitlab-ci and it will store your secrets separately from the repo in the project settings. You can easily configure it to deploy automatically, for example, whenever a tag is added.