Do you know integrating Snowflake and Slack can make your life as a data engineer much easier?
Here's why:
- Real-time error catching and debugging: Instead of constantly checking logs for errors, you can set up Snowflake to automatically ping you in a Slack channel when something goes wrong. This is like having a dedicated assistant who watches for errors in your code and immediately lets you know so you can fix them faster. This is achieved through the use of webhooks, which are essentially automated HTTP requests that Snowflake sends to Slack when triggered by an event.
- Keep everyone in the loop: Slack integration also means you can keep your entire team informed about the status of data pipelines and other processes. You can configure Snowflake to send notifications to a shared channel whenever a pipeline completes, fails, or encounters an issue. This keeps everyone on the same page and avoids unnecessary status update meetings.
This integration turns Slack into a powerful hub for managing your data workflow, making your life as a data engineer simpler and more productive.
How to Integrate Snowflake and Slack
Using Snowflake’s NOTIFICATION INTEGRATION function and Slack’s Webhooks feature it is possible to send messages to Slack from Snowflake.
This method can be used to send messages to Microsoft Teams and PagerDuty as well.
If you are not familiar with Slack, you can watch this video to get a quick overview of Slack.
Webhook is a http request. It is API call sometimes called reverse API or Push API. The defining feature of webhook is that the client instructs the server to callback (send http request to) the client when some event happens. In our case, the client, slack app, instructs the Snowflake to call (make a http request to an url endpoint) when some kind of event happens.
It is more about point of view: from which side you look at the process. From the Snowflake side, it is a regular API call, making a post request to Slack. But from the Slack side it is webhook (reverse API call) i.e, asking Snowflake to callback when an event occurs at a specific endpoint.
Steps
On Slack side
- Create a channel for testing purposes (optional)
- Create Slack app
- Integrate app to the channel
- Get app’s webhook URL
-
Creating a channel for testing purposes (optional)
-
Login to Slack, From Sidebar on the left click on “Add channels” button
-
Enter channel name
-
Choose channel visibility
public channels are visible to everyone within the workspace.
private channels are visible to people who are invited.
-
Click on the “Create” button
-
-
Creating Slack App
-
Open Slack Apps’s Dashboard page
-
Click on “Create App” button
-
Select “From Scratch” option
-
Enter App name and choose Workspace from drop-down
-
Click “Create App” button
-
-
Integrating the app to the channel
-
On the App settings page, click “Incoming webhooks” link on the left sidebar
If you had closed the tab, you can find your app from Slack app dashboard
-
Toggle on “Activate Incoming Webhooks”
-
Go to the bottom and click “Add New Webhook to Workspace” button
-
Choose the channel you want to connect the app to and click “Allow” button
After Integration on the channel you can see the new message confirming it
-
-
Getting App’s webhook URL
On App’s settings page Incoming Webhooks section go to bottom and copy “Webhook Url”, we will use it soon.
Note: App integration to a channel creates a unique Webhook Url for each channel。
What it means is that if you want to send messages to a different Slack channel from Snowflake, that channel should also be connected to the app and uniquely generated Webhook URL for that channel should be used on the Snowflake side.
On Snowflake Side
-
Storing Webhook Url’s token as a secret
Necessary privileges:
- Create secret
- Read secret
- Use secret
Webhook Url looks like this:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
.
We will store the token that comes afterhttps://hooks.slack.com/services/
part as a secret on Snowflake.
CREATE OR REPLACE SECRET my_slack_webhook_secret TYPE = GENERIC_STRING SECRET_STRING = 'T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';
-
Creating NOTIFICATION INTEGRATION
Necessary privileges:
- CREATE INTEGRATION
- USAGE On INTEGRATION
CREATE OR REPLACE NOTIFICATION INTEGRATION my_slack_webhook_int TYPE=WEBHOOK ENABLED=TRUE WEBHOOK_URL='https://hooks.slack.com/services/SNOWFLAKE_WEBHOOK_SECRET' WEBHOOK_SECRET=my_db.my_schema.my_slack_webhook_secret WEBHOOK_BODY_TEMPLATE='{"text": "SNOWFLAKE_WEBHOOK_MESSAGE"}' WEBHOOK_HEADERS=('Content-Type'='application/json');
SNOWFLAKE_WEBHOOK_SECRET
andSNOWFLAKE_WEBHOOK_MESSAGE are p
laceholders for a secret (in our case Webhook url token) and a message.
-
Calling NOTIFICATION INTEGRATION function
CALL SYSTEM$SEND_SNOWFLAKE_NOTIFICATION( SNOWFLAKE.NOTIFICATION.TEXT_PLAIN( SNOWFLAKE.NOTIFICATION.SANITIZE_WEBHOOK_CONTENT('Hello Slack!') ), SNOWFLAKE.NOTIFICATION.INTEGRATION('my_slack_webhook_int') );
SNOWFLAKE.NOTIFICATION.SANITIZE_WEBHOOK_CONTENT
removes placeholders (for example, the SNOWFLAKE_WEBHOOK_SECRET placeholder, which specifies a secret) from the body of a notification message to be sent.
If this function is not used and the message body contains a placeholder for a secret, then when a message is sent to a Slack webhook, a message containing a secret will be exposed to the Slack channel.The rest are set functions to be used with NOTIFICATION INTEGRATION to send a message.
Result
If calling 4 functions and stored procedures every time to send a message to a Slack is bothersome, a wrapper stored procedure can be used to simplify the process.
CREATE OR REPLACE PROCEDURE post_on_slack(message)
RETURNS FLOAT
LANGUAGE SQL
AS
BEGIN
CALL SYSTEM$SEND_SNOWFLAKE_NOTIFICATION(
SNOWFLAKE.NOTIFICATION.TEXT_PLAIN(
SNOWFLAKE.NOTIFICATION.SANITIZE_WEBHOOK_CONTENT(message)
),
SNOWFLAKE.NOTIFICATION.INTEGRATION('my_slack_webhook_int')
);
END;
Call post_on_slack('Hello Slack!')
Comments
Post a Comment