<@ULVA73B9P> how to use environment variables in a...
# marvin-in-the-wild
j
@Marvin how to use environment variables in a YAML configuration deployment
m
To use environment variables in a YAML configuration deployment in Prefect, you can add a
job_variables
section to your deployment definition in the
prefect.yaml
file. Here is a guide on how to achieve that: ### Hard-coded Job Variables To provide environment variables directly in the YAML file:
Copy code
yaml
deployments:
- name: demo-deployment
  entrypoint: demo_project/demo_flow.py:some_work
  work_pool:
    name: local
  job_variables:
    env:
      EXECUTION_ENVIRONMENT: staging
      MY_NOT_SO_SECRET_CONFIG: plumbus
  schedule: null
Run the deployment using:
Copy code
prefect deploy -n demo-deployment
You can then see the job variables in the Configuration tab of the deployment UI. ### Using Existing Environment Variables If you want to use environment variables that are already set in your local environment, you can template these in the YAML file:
Copy code
yaml
deployments:
- name: demo-deployment
  entrypoint: demo_project/demo_flow.py:some_work
  work_pool:
    name: local
  job_variables:
    env:
      EXECUTION_ENVIRONMENT: ${EXECUTION_ENVIRONMENT}
      MY_NOT_SO_SECRET_CONFIG: ${MY_NOT_SO_SECRET_CONFIG}
  schedule: null
Ensure the variables are set in your local environment before running the deployment. For further details and examples, check out the relevant Prefect guide. Keep in mind some issues raised in GitHub, like environment variables precedence and module imports, which might affect complex use cases: - GitHub Issue about precedence and environment variable handling - GitHub Issue discussing local package imports and PREFECT.yaml usage You can directly refer to the documentation here for more insights: Prefect Deployment Variables.