Report this

What is the reason for this report?

Environment variables being deleted after every deploy on DigitalOcean Functions

Posted on April 11, 2024

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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.