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.
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).
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.