Report this

What is the reason for this report?

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

Posted on April 3, 2023

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!



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

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.