https://prefect.io logo
Title
t

Theo Platt

04/20/2023, 7:03 PM
We've been migrating a flow from v1 to v2 and that's all working out fine. However, in v1 we would invoke a flow from Python using code a little like this -
from prefect.client.client import Client

c = Client(api_token='xxxxxxxxxx')
params = {'param1': 'Foo', 'param2': 'Bar'}
c.create_flow_run(
  version_group_id='xxxx-xxxxxx-xxxxxx-xxxxx', 
  run_name='my_run_name',
  parameters = params)
But I can't see a good example of how to do the same with v2! I think I'm missing something fundamental! Thanks
1
z

Zanie

04/20/2023, 7:04 PM
For v2 you use
run_deployment
t

Theo Platt

04/20/2023, 7:05 PM
Ahh. thanks. This is probably the logical leap I needed!
@Zanie Do you have a fuller example? I'm still a little lost as how to authenticate etc
z

Zanie

04/20/2023, 9:41 PM
You can login with
prefect cloud login
— the variables needed for authentication in other contexts can then be viewed with
prefect config view
(the API URL and API KEY are the relevant ones). You don’t need to provide a client manually to
run_deployment
it’ll read settings from the environment.
Then you’d just give a name i.e. if you’d run
prefect deployment run hello/test
you’d do
run_deployment(name="hello/test")
t

Theo Platt

04/20/2023, 9:43 PM
Oh right - so if I have the API URL and API KEY as environment variables in my (in this case) AWS lambda function, the run_deployment will pick up on those?
That's working! Thank you so much!
🙌 1
z

Zanie

04/20/2023, 10:18 PM
Exactly. Wonderful :)