@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.
npm install @architect/env
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 toSecureString
.
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
.
Queries SSM's getParametersByPath
, providing the arc appname
as the Path
parameter.
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:
- The first element must be the environment, one of
testing
,staging
, orproduction
. - 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.
- The third element must be the environment variable value. The value must be alphanumeric.
Removes an environment variable from the system using SSM's deleteParameter
.
opts
should be an array of three elements:
- The first element is ignored.
- 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.
- The third element must be the environment variable value. The value must be alphanumeric.
Pretty-prints environment variables and errors.
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.