https://prefect.io logo
Title
m

Mike Larsson

06/09/2022, 8:39 PM
hi folks, i have a question about agent-specific flow config. is there a way to make config available in a flow where the value will depend on the agent it's running in?
k

Kevin Kho

06/09/2022, 8:40 PM
I don’t believe there is a way. What config are you trying to set? Maybe we can do it through a state handler?
m

Mike Larsson

06/09/2022, 8:41 PM
our agents represent different regions, and we want to do things like connect to different databases depending on which region the flow is running in.
k

Kevin Kho

06/09/2022, 8:43 PM
I understand, by agent config you don’t mean Prefect Automations right? I think for your use case, you can do:
prefect agent something start --env IDENTIFIER=value_here
and then in the Flow, you have access to that env variable
import os

@task
def mytask
    os.environ["IDENTIFIER"]
m

Mike Larsson

06/09/2022, 8:43 PM
so the current plan is to use AWS Secrets Manager to manage the config for the different environments, but we were trying to find a nice way to get flows to look up the correct config based on the agent they're in
ah, ok
i was wondering about
--env
k

Kevin Kho

06/09/2022, 8:44 PM
Yes putting it there starts the flow with that env variable
m

Mike Larsson

06/09/2022, 8:44 PM
we tried setting environment in a YAML file and passing it in with
--task_definition
but that's not available to the flow, right?
k

Kevin Kho

06/09/2022, 8:45 PM
that’s the env of the agent process. the --env sets a different environment variable on the agent that is looked at
m

Mike Larsson

06/09/2022, 8:45 PM
got it, thanks!
k

Kevin Kho

06/09/2022, 8:46 PM
This is the env var under the hood I think that is looked at to pass through
- name: PREFECT__CLOUD__AGENT__ENV_VARS
          value: '{"test": "test2"}'
:thank-you: 1