https://prefect.io logo
Title
n

Nick Hoffmann

01/20/2023, 7:19 PM
Hey all, I'm exploring migrating from v1 to v2, and was looking to set up Notifications to a Slack channel. We have prefect-orion deployed via the helm chart, and currently have the Webhook url stored in an AWS Secret and would like to keep accessing it from there, but the only documentation I could find is for setting it up through the UI here. Is it possible to establish notification connections from outside the UI at all?
a

Anna Geller

01/20/2023, 7:31 PM
and you can create notification blocks via Python code
from prefect import flow, task
from prefect.blocks.notifications import SlackWebhook


@task
def send_alert():
    slack_webhook_block = SlackWebhook.load("yourblock") 
    slack_webhook_block.notify("Hello from Prefect!") 

@flow(name="Important-2.0-Flow")
def notification_flow():
    send_alert()
to set up:
from dotenv import load_dotenv
import os
from prefect.blocks.notifications import SlackWebhook

load_dotenv()

slack = SlackWebhook(url=os.environ.get("SLACK_WEBHOOK_URL"))
slack.save("default", overwrite=True)
n

Nick Hoffmann

01/20/2023, 7:45 PM
gotcha, thank you!
🙌 1