Vamsi Reddy
11/17/2021, 4:44 PMAnna Geller
Vamsi Reddy
11/17/2021, 4:52 PMKevin Kho
archived=False
Nate
11/17/2021, 4:54 PM# kick-off flow run with prefect.Client instance
def trigger_flow_run(params: Dict[str, Any]) -> dict:
prefect_client = prefect.Client(api_key=PREFECT_AUTH_TOKEN)
return prefect_client.create_flow_run(
parameters=params,
version_group_id=os.getenv('PREFECT_VERSION_GROUP_ID'),
)
here's a piece of a lambda I'm currently using to trigger flow runs, which does trigger the most recent flow versionVamsi Reddy
11/17/2021, 4:56 PMVamsi Reddy
11/17/2021, 5:02 PMKevin Kho
Vamsi Reddy
11/17/2021, 5:04 PM## prep the request
req = urllib.request.Request(os.getenv("PREFECT__CLOUD__API"), data=data)
req.add_header("Content-Type", "application/json")
req.add_header(
"Authorization", "Bearer {}".format(os.getenv("PREFECT__CLOUD__API_KEY"))
)
## send the request and return the response
resp = urllib.request.urlopen(req)
return json.loads(resp.read().decode())
Kevin Kho
Vamsi Reddy
11/17/2021, 5:07 PMKevin Kho
version_group_id
instead of the flow_id
because that is not modified during registration. The create_flow_run
Mutation in the GraphQL API can take in the version_group_id
directly. You can do a request like you are doing to this API endpoint.Vamsi Reddy
11/17/2021, 5:12 PMversion_group_id
instead of the flow_id
. I will give it a try.Anna Geller
import requests
query = """
mutation {
create_flow_run(input: { version_group_id: "fb919cc4-7f74-4ed7-9f3c-71bdd9be69e8" }) {
id
}
}
"""
url = "<https://api.prefect.io>"
response = <http://requests.post|requests.post>(
url, json={"query": query}, headers={"authorization": "Bearer XXX"}
)
print(response.status_code)
print(response.text)