Question

How to specify environment variables in the project.yml file for App Functions?

I am trying to specify two environment variables that are needed to perform some functionality on my application. I try to specify them as follows:


services:
    envs:
    - key: MY_FIRST_VAR
      scope: BUILD_AND_RUN_TIME
      value: a_key_value
    - key: A_UNIQUE_KEY
      scope: BUILD_AND_RUN_TIME
      value: 123456789asdf

packages:
  - name: sample
    actions:
      - name: hello
        runtime: 'python:default'

I tried to mimic what I saw here

When I try to build, though, I get a message:

›   Error:   : Invalid project configuration file (project.yml): Invalid key 
›   'services' found in project.yml

I have tried mixing things around and trying different combinations, however I’m stuck as to how to go about this. I tried defining the environment variables through the GUI, however they were not recognized by my python program that needed them.

If you need any other information for about this to help let me know!


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 4, 2023

Hi there,

You should be able to define environment variables as follows:

packages:
  - name: sample
    environment:
        DATABASE_URL: "${DATABASE_URL}"
    actions:
      - name: hello
        runtime: 'python:default'

Here are some more examples as well:

https://docs.digitalocean.com/products/functions/reference/project-configuration/#examples

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

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

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

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
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