!env
The !env
Atmos YAML function is used to retrieve environment variables
and assign them to the sections in Atmos stack manifests.
Usage
The !env
function can be called with either one or two parameters:
# Get the value of an environment variable.
# If the environment variable is not present in the environment, `null` will be assigned
!env <env-var-name>
# Get the value of an environment variable.
# If the environment variable is not present in the environment, the `default-value` will be assigned
!env <env-var-name> <default-value>
Arguments
env-var-name
Environment variable name
default-value
- (Optional) Default value to use if the environment variable is not present in the environment
If the function is called with one argument (the name of the environment variable), and the environment variable is
not present, null
will be assigned to the corresponding section in the Atmos manifest.
If the function is called with two arguments (the name of the environment variable and the default value), and the environment variable is not present, the default value will be assigned to the corresponding section in the Atmos manifest.
Examples
vars:
# `api_key` will be set to `null` if the environment variable `API_KEY` is not present in the environment
api_key: !env API_KEY
# `app_name` will be set to the default value `my-app` if the environment variable `APP_NAME` is not present in the environment
app_name: !env APP_NAME my-app
settings:
# `provisioned_by_user` will be set to `null` if the environment variable `ATMOS_USER` is not present in the environment
provisioned_by_user: !env ATMOS_USER
Handling default values with spaces
If you need to provide default values with spaces, enclose them in double quotes and use single quotes around the whole expression.
For example:
# `app_name` will be set to the default value `my app` if the environment variable `APP_NAME` is not present in the environment
app_name: !env 'APP_NAME "my app"'
# `app_description` will be set to the default value `my app description` if the environment variable `APP_DESCRIPTION` is not present in the environment
app_description: !env 'APP_DESCRIPTION "my app description"'
You can use Atmos Stack Manifest Templating in the environment variable names and default values when calling the !env
YAML function.
Atmos processes the templates first, and then executes the !env
function, allowing you to provide the parameters to
the function dynamically.