Thread
#prefect-community
    m

    Mike Larsson

    3 months ago
    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?
    Kevin Kho

    Kevin Kho

    3 months ago
    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

    3 months ago
    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.
    Kevin Kho

    Kevin Kho

    3 months ago
    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

    3 months ago
    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
    Kevin Kho

    Kevin Kho

    3 months ago
    Yes putting it there starts the flow with that env variable
    m

    Mike Larsson

    3 months ago
    we tried setting environment in a YAML file and passing it in with
    --task_definition
    but that's not available to the flow, right?
    Kevin Kho

    Kevin Kho

    3 months ago
    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

    3 months ago
    got it, thanks!
    Kevin Kho

    Kevin Kho

    3 months ago
    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"}'