Are DEPLOY_URL, DEPLOY_PRIME_URL available outside of netlify.toml?

I know we can use $DEPOY_URL and friends inside netlify.toml's build command settings.

Ideally I would love to be able to use such variables from within functions.

My use case requires calling an absolute permalink from within a Lambda Function and I’d rather use a dynamic solution à la process.env.DEPLOY_PRIME_URL which would securely use the right URL regardless of context.


Hi @regisphilibert , this is something that we are working on adding. At the moment the only environment variables available inside of functions are those specified in the UI.


Got it! Thanks @futuregerald.

1 Like

Oh actually you can already, just not sure how stable it is but it lives inside process.env.DEPLOY_URL alongside process.env.URL

1 Like

Yes, it is accessible at build time from the shell in the process.env hash, but not during function invocation unless you have applied the value during build (as in, put its value into your function’s code directly rather than referring to it at function invocation time).

Could you explain how to do this within a netlify lambda function?

I have a function that has a baseUrl that I need to be different for local/branch deploys/production:

const baseUrl = (process.env.context === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL) || 'http://localhost:8888';

DEPLOY_PRIME_URL is undefined because it’s during a function invocation. Is there another way to apply this?

To access that env var, you could try injecting the value of that var into your function directly similar to what is shown here: File-based configuration | Netlify Docs.

To say Dennis’ suggestion in another way, you’d have to manually take the value you can see during build, and put it into a file, which is itself available during function execution to read from.

So it seems I’d have to manually set DEPLOY_PRIME_URL somewhere whether in my code or other file for use in my functions/. Even thought URL is available and automatically set.

I guess I could consider having my endpoint accept a url in the body of my request since my web app has access to DEPLOY_PRIME_URL

Hey @tettoffensive,
Yup, you’ll have to write DEPLOY_PRIME_URL to a file that your function then loads. Here’s how someone’s writing the variable to a file in a prebuild script, then loading that file in their function:

Definitely not ideal, but wanted to share since it’s an actual implementation you can take a look at.

1 Like

Thanks, @jen! This is really helpful!

1 Like