exalted / architect_env

Manage an Architect project's environment variables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@architect/env GitHub CI status

@architect/env reads and writes environment variables that are made immediately available to all deployed Functions. Sensitive configuration data, such as API keys, needs to happen outside of the codebase in revision control and you can use this tool to ensure an entire team and the deployment targets are in sync.

Installation

npm install @architect/env

Use of AWS SSM

This modules stores environment variables as AWS SSM Parameters using AWS SSM Parameter Store. Parameters are created such that:

  • each Parameter's Name stores environment variables in the format ${appname}/${environment}/${variableName}.
  • each Parameter's Value stores the environment variable value.
  • each Parameter's Type is set to SecureString.

API

env(options, callback)

Reads, writes and/or prints environment variables based on the contents of opts.

opts is an array. If no callback is provided, returns a Promise.

If opts is the empty array, invokes env.all, prints the results via env.print and writes them to disk using [env.write][write].

if opts is an array of three elements and the first element is one of the strings testing, staging or production, will invoke env.add.

if opts is an array of three elements and the first element is one of the strings remove, --remove or -r, will invoke env.remove.

env.all(appname, callback)

Queries SSM's getParametersByPath, providing the arc appname as the Path parameter.

env.add(appname, opts, callback)

Adds an environment variable to the system using SSM's putParameter, overwriting any Parameter with the same Name. opts should be an array of three elements:

  1. The first element must be the environment, one of testing, staging, or production.
  2. The second element must be the environment variable name. The name must be all caps and may contain underscores. It cannot be a reserved word.
  3. The third element must be the environment variable value. The value must be alphanumeric.

env.remove(appname, opts, callback)

Removes an environment variable from the system using SSM's deleteParameter. opts should be an array of three elements:

  1. The first element is ignored.
  2. The second element must be the environment variable name. The name must be all caps and may contain underscores. It cannot be a reserved word.
  3. The third element must be the environment variable value. The value must be alphanumeric.

env.print(error, result)

Pretty-prints environment variables and errors.

env.write(result)

Writes result into an .arc-env file in the current working directory in a format that lists out all environment variables per testing, staging and production environments.

About

Manage an Architect project's environment variables

License:Apache License 2.0


Languages

Language:JavaScript 100.0%