On Astro, an Environment Variable is a key-value configuration that can be set at the Deployment or Workspace level. You can use environment variables to configure custom environment variables for your Deployments, customize core settings of Airflow and its pre-installed providers, or store Airflow connections and variables.
Some scenarios where you might use environment variables in your Deployment include:
Some examples of customizing core settings of Airflow or any of its pre-installed providers include:
AIRFLOW__CORE__DAGBAG_IMPORT_TIMEOUT.You can also use environment variables to store Airflow connections and variables.
Some environment variables on Astro are set globally and can’t be overridden for individual Deployments, while others are used by Astro Runtime to enhance your Airflow experience. For more information on these, see Global environment variables.
Environment variables can be used in many different contexts on Airflow. To choose the right management and implementation strategy for your specific use case, it’s helpful to know how Astro prioritizes and stores environment variables for each available management option.
On Astro, you can manage environment variables from three different locations:
At the local development level, you can use your Astro project .env file to set and test environment variables. When you’re ready to push these environment variables to a Deployment, you can use the Astro CLI to export and store them in the Astro UI for your Deployment.
When you set a non-secret environment variable in the Deployment UI, Astronomer stores the variable in a database that is hosted and managed by Astronomer.
When you set a secret environment variable in the Deployment UI, the following happens:
env-secrets, that contains your variable’s key and value.This process occurs every time you update the environment variable’s key or value. The Deployment restarts when Deployment-level environment variables are saved.
When you create an environment variable in the Workspace Environment Manager, Astro stores the environment variable in an Astronomer-hosted secrets manager and applies it to Deployments as Kubernetes Secrets. See How environment variables are stored for details.
Environment variables marked as secret are stored securely by Astronomer and are not shown in the Astro UI. However, it’s possible for a user in your organization to create or configure a Dag that exposes secret values in Airflow task logs. Airflow task logs are visible to all Workspace members in the Airflow UI and accessible in your Astro cluster’s storage.
To avoid exposing secret values in task logs, instruct users to not log environment variables in Dag code.
On Astro, environment variables are applied in the following order of precedence, from highest to lowest:
For example, if you set AIRFLOW__CORE__PARALLELISM with one value in the Deployment UI, another value in the Workspace Environment Manager, and a third value in your Dockerfile, the value set in the Deployment UI takes precedence.
When you view environment variables in a Deployment’s Environment Variables page, you’ll see a unified view of both Deployment and Workspace environment variables, with clear indicators showing the source and any overrides.
Similarly, in local development, environment variables set in your .env file take precedence over environment variables set in your Dockerfile.
For most use cases, Astronomer recommends using the Astro UI to store your environment variables for the following reasons:
There are some scenarios when you might want to use a mix of methods or strategies other than the Astro UI. The following table prescribes specific methods for various common use cases.