<@ULVA73B9P> if I wanted to deploy a notification ...
# ask-marvin
j
@Marvin if I wanted to deploy a notification automation in github actions along with my deployments, can I do that in
prefect.yaml
? This is not an automation to trigger the deployment, but based off the deployment. Suggest other options if not.
m
thought for 874.0 seconds
Short answer: not today. In Prefect 3.x,
prefect.yaml
is for defining deployments and build steps; it doesn’t support defining Automations. Automations are separate, event-driven objects in Prefect. Good alternatives you can ship from GitHub Actions alongside your deployments: 1) Put notifications in your flow code (state hooks) - This keeps it versioned with your code and deployed via
prefect.yaml
. - Example using a Slack Webhook block:
Copy code
from prefect import flow
from prefect.blocks.notifications import SlackWebhook

# Create/load a Slack block named "alerts" in Prefect once (UI or Python), then load it here
slack = SlackWebhook.load("alerts")

def alert_on_failure(state):
    # `state` is the terminal flow state; you can format a detailed message if you want
    slack.notify("Flow run failed")

@flow(name="my-flow", on_failure=[alert_on_failure])
def my_flow():
    # your flow code
    ...
- Slack integration docs: Prefect Slack integration 2) Create or manage an Automation in CI using the API (not
prefect.yaml
) - You can script Automation creation/update with the Prefect API/Python client in a GitHub Actions step, using `PREFECT_API_KEY`/`PREFECT_API_URL`. - Note: in this environment the CLI help does not expose an “automation create” command; the supported automation CLI subcommands we can confirm are list/inspect/pause/resume/enable/disable/delete: prefect automation CLI. - If you want to go this route, I can help you scaffold a small Python script that: - Checks for an existing Automation targeting your deployment’s events - Creates or updates it to send a Slack/Email/Teams notification (SendNotification action) 3) Create the Automation once in the UI, target your deployments, and keep it environment-agnostic - Use filters like deployment name or tags and choose Send Notification. - This is the quickest if you don’t need to manage it as code. A couple of notes: - There isn’t first-class support to define Automations in
prefect.yaml
. - Terraform support for Automations isn’t available at this time (it focuses on deployments/work pools). - Verified CLI commands for Automations: prefect automation CLI - Python Automations API reference (for building programmatic scripts): Automations API reference If you share: - the notification channel (Slack/Teams/Email/Webhook), - when to notify (failures only, completion, etc.), - whether it should be scoped to a single deployment or a set (by tags/names), I can provide a ready-to-drop-in GitHub Actions step (either as a flow-state hook example or a small Python script that ensures the Automation exists).