https://prefect.io logo
l

Lawrence Finn

08/03/2021, 5:45 PM
Is there a way to set the api_token in code rather than relying on env or config file?
k

Kevin Kho

08/03/2021, 6:14 PM
Hey @Lawrence Finn, I will double check this but I don’t think so. You can authenticate the
Client
, but that would but extend to
flow.register()
l

Lawrence Finn

08/03/2021, 6:17 PM
i had to do something like
Copy code
os.environ["PREFECT__CLOUD__AUTH_TOKEN"] = get_prefect_token()

from prefect import task, Flow, Parameter
from prefect.schedules import IntervalSchedule
from datetime import timedelta
from prefect.storage import S3
from prefect.executors import DaskExecutor
from prefect.run_configs import KubernetesRun
from prefect.tasks.prefect import StartFlowRun
import prefect
which is kinda ugly but 🤷
im writing an aws lambda and the api token is a secret in aws secret store
k

Kevin Kho

08/03/2021, 6:21 PM
I went through the code and you might be able to do
Copy code
client = Client(api_key="...")
client.save_auth_to_disk()
which creates an
auth.toml
file and then future
Client()
calls would fetch that so when you do
flow.register()
, it would work as it creates a client under the hood. But this would persist a file which I guess is not what you want.
I see what you mean. Yeah I guess that’s what you have to do.
l

Lawrence Finn

08/03/2021, 6:23 PM
i guess your solution is fine, it’s on a lambda container so it is fine to write the file
k

Kevin Kho

08/03/2021, 6:30 PM
Actually, if you do it this way, just use the
client.register()
function directly to register your Flow.
l

Lawrence Finn

08/03/2021, 6:44 PM
what params does that func take?
k

Kevin Kho

08/03/2021, 6:46 PM
Very similar:
Copy code
prefect.client.client.Client.register(flow, project_name=None, build=True, set_schedule_active=True, version_group_id=None, compressed=True, no_url=False, idempotency_key=None)
l

Lawrence Finn

08/03/2021, 7:17 PM
oh cooool
thanks 🙏
2 Views