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?

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

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

def notification_flow():
to set up:
from dotenv import load_dotenv
import os
from prefect.blocks.notifications import SlackWebhook


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

Nick Hoffmann

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