Serverless Design Patterns and Best Practices
上QQ阅读APP看书,第一时间看更新

Configuration with environment variables

If you're familiar with the Twelve-Factor App or have worked with Docker much, you'll know that configuration may be done using environment variables rather than managing multiple disparate configuration files. According to The Twelve-Factor App (https://12factor.net/config):

"Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard."

Using environment variables for FaaS enables code deployments to different systems (dev, QA, production, and so on). Changing configuration can be as simple as updating a variable in your function's config. However, for safety and repeatability, environment variable changes should go through some process such as CI/CD to minimize the chance of errors.

On the flip side, if using file-based configuration, updating the application typically requires updating a file, possibly checking into source control and redeploying the entire application.

In my opinion, there is an enormous increase in productivity using environment variables when creating new systems or deploying between different systems. To perform a new stack deployment or update of an existing stack, you merely load up new environment variables and executes a standard set of steps that don't change between stacks. Due to the ease and speed with which you can do this, it encourages separation of stacks for different purposes (development, testing, production, and much more).