By xerinae
Hi,
I’m working on a Python function being deployed to Functions and it needs to access API keys and other secrets. I added the secrets to the environment variables section on the settings page for the function (via the web UI), but all the environment variables get deleted after each doctl serverless deploy package-name --remote-build command.
I thought it might’ve been because in project.yml I had set environment: {}, so I removed environment: {} and it’s now a barebones project.yml file. Even after that change, the environment variables are gone after every update I deploy.
Is there a way to persist the environment variables across doctl serverless deploys of the same function? Or am I setting something wrong to cause this behavior?
Thanks
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!
Hi there,
You would actually need to explicitly declare the environment variables in the project.yml.
That way you can ensure the env variables are set with every deployment, eg:
functions:
myfunction:
handler: functions/handler.my_handler
environment:
API_KEY: "your_api_key_here"
ANOTHER_SECRET: "your_secret_here"
Otherwise, as you mentioned that your project.yml had an empty environment: {} block, which you later removed, if environment: {} is set, it will override environment variables set via the web UI during deployment as the platform will try to match whatever is in the project.yml file.
Let me know how it goes!
Best,
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.