I have 2 namespaces - one for production and one for development. In each namespace, I maintain 3 functions. For the production namespace, I have configured the variable NODE_ENV to production. Similarly for the development namespace, I have set the NODE_ENV env variable to development. I have done so for each function. I am doing this so that I can have my code reference production and development config setting files by looking up “.env.<NODE_ENV>” files, which have been packaged with the code.
Here’s what I have observed. With every update of the function, I see that all the env variables configured, via the DO functions web interface, get deleted.
Is this normal behaviour and if so how can I fix this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey Prashant!
Yep, I think that this is expected behavior right now.
As far as I’m aware, when you update a DigitalOcean Function using doctl
, it replaces the entire function definition, including any environment variables, unless they’re part of the update.
To avoid losing them, you’ll want to define your environment variables in your project.yml
or in the .do
directory if you’re using doctl deploy
. Something like:
functions:
my-function:
env:
NODE_ENV: production
This works well for non-sensitive values like NODE_ENV
. Just be careful not to hardcode any secrets or API keys into that file if you’re committing it to version control.
If you need to handle secrets, you can load them in during your deployment process instead, or manage them separately depending on your workflow.
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.