Hi team, is it possible to export the yaml for an ...
# prefect-cloud
l
Hi team, is it possible to export the yaml for an automation created in the prefect UI?
w
Hey LielA, you can hit the /automations API to get that spec, or if its a one time thing you can actually grab it from the network tab of devtools 🙈
both would be in json form, but close enough
and we're working on some features to make this easier from the UI
l
Thanks Will! To be more specific, we are looking to create an automation via a new deployment using a trigger as described here https://docs.prefect.io/latest/concepts/automations/#create-an-automation-via-deployment-triggers. Would it be the automation or deployment API that provides a similar (json) structure?
w
good question, they actually both will. when you add a trigger to a deployment, under the hood it creates an automation, and links the two. so you could call either API and get the same information.
I think the automation itself will have slightly more information
l
Thank you! When created with a deployment trigger in yaml, is the name of the automation inferred from the deployment name? (not clear in the docs if we can specify an automation name via this route)
w
its inferred by like {deployment}__trigger. you can always patch that after, but if you'd like to be able to specify a name there, go ahead and file a github issue, that's a quick win.
l
not terribly concerning at this point, but good to know 🙂 ! Thank you for your help Will. I have an unrelated question in the k8s channel but not sure if i've worded it properly. is that something you can shed light on?
w
No problem. That question is worded in a way that makes total sense to me, but i dont know the answer. Lets see if anybody in that channel does else I can ping a colleague.
🤞 1
l
thank you 🙂
Follow up question related to deployment triggers: in the yaml, is it possible to use parameters for the matching flow (flow state change trigger) as parameters in the deployment being created?
w
I think so! what time zone are you on, want to pair a bit on it Monday? Might be easier. else happy to continue here on slack
l
I'm in CST, on for another hour or so. Happy to pair on monday! are there some steps you can send me on slack in the meantime?
w
oh nice im CST too, but yeah for now: i think what you'll want to do is: At flow completion just as the last line in the flow code, emit a custom event, something like, and sorry this is pseudocode just cause im running out the door in a sec
Copy code
emit_event(
{"event": "my-custom-flow-run-event"}
"resource": prefect.runtime.flow_run_id
payload{ all my parameters and stuff
}
)
Then, trigger your automation based on that event, and in the run deployment action, you can pass values from the triggering event into that action with jinja syntax, so the parameter of the flow run you're creating could have like {{ event.payload.paravalue }}. The one hang up is that the input parameters of the new flow need to be strings.
The actions in an automation always have access to the event object that triggered it for use in stuff like this.
l
thank you Will! for states outside of completion (failure or otherwise), we would need a different approach? i suppose we could emit the event early in the flow
w
You could consider using state change hooks here, but the issue is that sometimes if the flow crashes, its for reasons that also render the state change hook unexecutable (i.e your box crashed)
l
excellent! thank you Will. enjoy your weekend