Question

Environment variables being deleted after every deploy on DigitalOcean Functions

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


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
April 14, 2024

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel