https://prefect.io logo
s

Soren Daugaard

09/07/2022, 5:01 PM
What is the best way to set a configuration value programmatically? I need to be able to load the
PREFECT_API_KEY
from secrets manager and set it in my Python code when creating a new Prefect client. Is something like this the right approach:
Copy code
from prefect.settings import PREFECT_API_KEY

async def start_flow(flow_deployment_name, params):
    secret_key = load_my_secret()
    with temporary_settings(updates={PREFECT_API_KEY: secret_key}):
        client = get_client()
        deployment = await client.read_deployment_by_name(name=flow_deployment_name)
        run = await client.create_flow_run_from_deployment(deployment.id, parameters=params)
        return run.id
I want to avoid using profiles because I would like to avoid having the secret stored on disk.
1
n

Nate

09/07/2022, 6:31 PM
in general
What is the best way to set a configuration value programmatically?
the answer is in a Block (in your case, a Secret block) but in your case, do you have access to a given workspace when you're trying to configure the client? if not I'd use something like boto3 to pull in the secret from secret manager