I am writing a small Lambda function to trigger a ...
# ask-community
k
I am writing a small Lambda function to trigger a prefect flow run on demand. I was wondering if anyone has done similar and could let me know if these queries look right • given a flow name, get the latest version’s id
Copy code
LATEST_FLOW_BY_NAME = gql(
    '''
        query LatestFlowByName($name: String) {
          flow(
            where: {name: {_eq: $name}},
            order_by: {version: desc},
            limit: 1,
          )
          {
            id
          }
        }
    ''',
)
with:
variable_values={'name': name}
• trigger a flow run
Copy code
CREATE_FLOW_RUN = gql(
    '''
        mutation CreateFlowRun($input: create_flow_run_input!) {
            create_flow_run(input: $input) {id}
        }
    ''',
)
with:
Copy code
variable_values={
    'input': {
        'flow_id': flow_id,
        'parameters': parameters,
    },
},
My goal here is to specify as little as possible, to ensure the flow runs with the defaults configured for it. I.E. I don’t want to muck with the RunConfig, etc. I am mostly concerned about my logic for getting the latest flow run. I tried to grok the flow groups / versions tables but did not have much luck.
k
Hey @Kyle McChesney, I think the concern here is that the
LatestFlowByName
is not guaranteed to pull the right now unless you immediately registered? You may also have different projects that contain a flow with the same name. The other queries look good to be.
k
Not sure I follow the first part. The flows are registered else where, as part of a CI process (when a PR is merged)
k
If you have two projects “A” and “B” that both contain a flow named “myflow”. How is it guaranteed you would get the “myflow” of project A?
k
oh I see, I misunderstood. Its all related to the flow name overlap issue. Assuming flow names are unique, this latest query should work?
k
I believe so. I haven’t used that route specifically but I expect it to yep
k
much appreciated @Kevin Kho!