From 8ae4c7e2edb063f5090edabb3ed3ed5d948cfc17 Mon Sep 17 00:00:00 2001 From: Erin Cochran Date: Thu, 16 Nov 2023 16:50:04 -0500 Subject: [PATCH] Add EnvVar vs os.getenv section --- .../using-environment-variables-and-secrets.mdx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/content/guides/dagster/using-environment-variables-and-secrets.mdx b/docs/content/guides/dagster/using-environment-variables-and-secrets.mdx index 9bdc996f286a4..8629f9c0d435b 100644 --- a/docs/content/guides/dagster/using-environment-variables-and-secrets.mdx +++ b/docs/content/guides/dagster/using-environment-variables-and-secrets.mdx @@ -106,7 +106,7 @@ Refer to the [Dagster Cloud Branch Deployments example](#example-2-dagster-cloud ### From Dagster configuration -[Configurable Dagster objects](/concepts/configuration/config-schema) - such as ops, assets, resources, I/O managers, and so on - can accept configuration from environment variables. Dagster provides a native way to specify environment variables in your configuration. These environment variables are retrieved at launch time, rather than on initialization as with `os.getenv`. +[Configurable Dagster objects](/concepts/configuration/config-schema) - such as ops, assets, resources, I/O managers, and so on - can accept configuration from environment variables. Dagster provides a native way to specify environment variables in your configuration. These environment variables are retrieved at launch time, rather than on initialization as with `os.getenv`. Refer to the [next section](##using-envvar-vs-osgetenv) for more info. @@ -147,6 +147,15 @@ Refer to the [Handling secrets section](#handling-secrets) and [Per-environment +### Using EnvVar vs os.getenv + +We just covered two different ways to access environment variables in Dagster. So, which one should you use? When choosing an approach, keep the following in mind: + +- **When `os.getenv` is used**, the variable's value is retrieved when Dagster loads the [code location](/concepts/code-locations) and **will** be visible in the UI. +- **When `EnvVar` is used**, the variable's value is retrieved at runtime and **won't** be visible in the UI. + + + --- ## Handling secrets @@ -249,7 +258,7 @@ defs = Definitions( Let's review what's happening here: -- We've created a dictionary of resource definitions, `resources`, named after our `local` and `production` environments. In this example, we're using a [Pandas Snowflake I/O manager](/\_apidocs/libraries/dagster-snowflake-pandas). +- We've created a dictionary of resource definitions, `resources`, named after our `local` and `production` environments. In this example, we're using a [Pandas Snowflake I/O manager](/_apidocs/libraries/dagster-snowflake-pandas). - For both `local` and `production`, we constructed the I/O manager using environment-specific run configuration. Note the differences in configuration between `local` and `production`, specifically where environment variables were used. - Following the `resources` dictionary, we define the `deployment_name` variable, which determines the current executing environment. This variable defaults to `local`, ensuring that `DAGSTER_DEPLOYMENT=PRODUCTION` must be set to use the `production` configuration.