Hello,
is there a way to set persistent env variables in netlify function execution environment programatically?
No, as far as I know, you can’ set environment variables programmatically. What you can do is access them programmatically. So, if there is a set of possible values your variable can have, you can set them as individual variables and access the correct variable according to your logic.
If you can provide more context as to what you’re trying to achieve, we can provide more info.
The set of possible values are too big, your solution won’t work. I want to store database credentials somewhere on server, using app ui, so the user not familiar with netlify could set it.
I think, you should then consider using services like FaunaDB or Firebase as a database instead of relying on environment variables. Would this option be feasible for you?
There are examples that could demonstrate how to connect to such tools from Netlify Functions.
I need to set credentials and later use them in netlify function initializing database and performing database query. So fetching credentials from database would take much longer than getting it from environment. Please don’t advice me what should I do, I have clear question and need answer only about it. Thanks
That was my first line.
So this answer is as far as you know. It not necessary the truth
hi rromikas! usually Hrishikesh is one of the most reliable people here in these forums as far as knowledge goes, but it is actually possible to set environment variables, either via the CLI or the API.
You can read here to learn more:
Hi, I see public API first time, awesome finding. I will probably need to use updateSite endpoint to edit build environment variables and after that I will need to trigger rebuild. That’s great. Thank you.