[Support Guide] Using environment variables on Netlify correctly

Sharing what worked for me, for a Netlify lambda function:

  1. Adding environment variables through Netlify’s UI widget (on the site’s “Build & Deploy settings” page).

  2. netlify.toml

[build]
    Command = "npm run lambda-build"
    Functions = "lambda"
  1. Adding node -p 'process.env' to my package.json lamba-build command:

"lambda-build": "netlify-lambda build functions && node -p 'process.env'"

This way, when the function is deployed, env variables will we loaded and available to the function.

2 Likes