# Toml environment variable available to functions

**URL:** <https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265>\
**Category:** Support\
**Tags:** lambda-functions, environment-vars\
**Created:** [October 17, 2019, 10:53am UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265 "2019-10-17T10:53:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![avk](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/avk/32/3531_2.png) [@avk](https://answers.netlify.com/u/avk)\
**Post date:** [October 17, 2019, 10:53am UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265/1 "2019-10-17T10:53:41Z")

</div>

I have been testing environment variables on deploy previews at the moment.

I have a `[context.deploy-preview.environment]` block in my `netlify.toml` file with some variables defined. I unfortunately am not able to access those variables in the functions via the process.env (or dotenv package). None of the variables in the `toml` file are available, but the variables defined via the netlify UI are there.

Is this an intended outcome or have i been making a mistake somewhere?

---

<div class="post-metadata">

**Author:** ![ozdanborne](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@ozdanborne](https://answers.netlify.com/u/ozdanborne)\
**Post date:** [October 18, 2019, 10:10pm UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265/2 "2019-10-18T22:10:38Z")

</div>

+1 I’m hitting this exact problem. The only environment variables my function picks up are those set through the netlify UI.

In the netlify docs, I found it suspicious that [this sentence](https://docs.netlify.com/configure-builds/environment-variables/) doesn’t mention that environment variables set in toml are picked up by functions:

> Environment variables set in the UI are also accessible in other environments associated with your site, including serverless functions at runtime, snippet injection during post processing, and more.

I’ve tried the following toml settings with no luck:

- `[build.environment]`
- `[context.branch-deploy.environment]`
- `[context.my-branch-name.environment]`

[Yet this example online suggests you can…](https://github.com/netlify/aws-lambda-go-example/blob/master/netlify.toml#L7)

---

<div class="post-metadata">

**Author:** ![talves](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/talves/32/101_2.png) [@talves](https://answers.netlify.com/u/talves)\
**Post date:** [October 18, 2019, 10:55pm UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265/3 "2019-10-18T22:55:28Z")

</div>

Only environment variables in the dashboard are available at the time of a function execution in Netlify Functions at the time of this answer. 😁

@ozdanborne The variable is not used in the function code. The variable in the `netlify.toml` is used by the build command for a GO build command. [See here](https://docs.netlify.com/functions/build-with-go/#build-settings-and-dependency-management)

---

<div class="post-metadata">

**Author:** ![lcfyi](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/lcfyi/32/3865_2.png) [@lcfyi](https://answers.netlify.com/u/lcfyi)\
**Post date:** [November 4, 2019, 6:22am UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265/4 "2019-11-04T06:22:40Z")

</div>

Just to verify, are you guys writing your functions and storing them in the directory you specified for your functions, or are you using netlify-lambda to build from another source folder into your designated functions directory?

I’ve been able to get deploy preview environment variables to work just fine for my lambdas, and I suspect it’s because of netlify-lambda which webpacks my output. Since it’s part of the build process, I’m able to use my context-specific variables that get bundled into the output.

---

<div class="post-metadata">

**Author:** ![futuregerald](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/futuregerald/32/33_2.png) [@futuregerald](https://answers.netlify.com/u/futuregerald)\
**Post date:** [November 4, 2019, 9:31pm UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265/5 "2019-11-04T21:31:21Z")

</div>

Hi @lcfyi

netlify-lambda is a great library, but it’s being deprecated in favor of “zip-it-and-ship-it” where we zip your node\_modules in with your function automatically. This already happens automatically. This is how I deploy new apps with functions, but I still have many that still use netlify-lambda to bundle the function.

---

<div class="post-metadata">

**Author:** ![Elyx0](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/elyx0/32/30323_2.png) [@Elyx0](https://answers.netlify.com/u/Elyx0)\
**Post date:** [October 27, 2021, 10:57am UTC](https://answers.netlify.com/t/toml-environment-variable-available-to-functions/4265/6 "2021-10-27T10:57:14Z")

</div>

I wrote [netlify-plugin-inline-functions-env-typescript - npm](https://www.npmjs.com/package/netlify-plugin-inline-functions-env-typescript) to fix that, check the `inlineAll` param, it might be what you need.
