Anthony W
02/04/2025, 2:46 PMMarvin
02/04/2025, 2:46 PMprefect.yaml
file to manage different deployment configurations without duplicating entries. This allows you to dynamically set values based on your environment (e.g., staging or production).
Here's how you can leverage environment variables in your `prefect.yaml`:
1. Environment Variables: You can use syntax like {{ $MY_ENV_VAR }}
to reference environment variables. This is particularly useful for setting values that change between environments, such as API keys, URLs, or other configuration settings.
2. Multiple Deployments: Prefect supports multiple deployment declarations within a single prefect.yaml
file. This allows you to manage different configurations for the same flow in one place. You can define separate sections for each environment and use environment variables to toggle between them.
For more details, you can refer to the Prefect documentation on YAML templating.
Here's an example snippet of how you might structure your `prefect.yaml`:
yaml
deployments:
- name: my-flow-staging
parameters:
api_url: "{{ $STAGING_API_URL }}"
- name: my-flow-prod
parameters:
api_url: "{{ $PROD_API_URL }}"
By setting the environment variables STAGING_API_URL
and PROD_API_URL
at runtime, you can switch between configurations without duplicating entire deployment entries.