Module 20 · Lesson 6 of 11Detailed study · about 32 min

Snowflake Alerts and Notifications: Schedules, New Data and Delivery Checks

Detect late or failed pipelines, route a notification to a test destination, and verify alert execution separately from message delivery.

Before you beginDefine the signal and delivery cutoff

Choose an alert on a schedule or on new data

An alert runs a SQL condition and, if it returns a row, runs an action. In warehouse-backed alerts, WAREHOUSE identifies the compute that runs both. A serverless alert omits WAREHOUSE and uses Snowflake-managed compute. The role still needs the correct privileges, and both options incur compute costs.

Use a schedule for silence, such as a missing file, a missed delivery deadline or a cost threshold based on the most recent completed usage interval. Use a new-data alert to react when a new row describes a problem. Omitting SCHEDULE makes a new-data alert. The condition is limited to a supported single regular table, view or event table with change tracking enabled. For example, a condition with joins or common table expressions is not supported. New-data alerts cannot be run manually with EXECUTE ALERT.

Follow an alert from condition to delivery The return value of the condition, action history and outbound message history answer separate questions.
  1. Audit or deadlineEvaluate to IF EXISTS
  2. IF EXISTSWhen true to One incident key
  3. One incident keyRoute to Approved receiver
Audit or deadline
Current pipeline evidence.
IF EXISTS
At least one row means the action should run.
One incident key
Record repeated violations once per delivery.
Approved receiver
Send, check delivery and track acknowledgement.

Prepare the role and test warehouse

Use the scratch database from the capstone and an approved warehouse called MAPLE_WH, or substitute its real name in each template. An administrator grants EXECUTE ALERT on the account; the alert owner also needs database and schema USAGE, CREATE ALERT on the schema, warehouse USAGE, and access to read the evidence and perform the action. Serverless alerts also require EXECUTE MANAGED ALERT. Use a narrow alert owner role. If the owner does not own the monitored table, the table owner should enable change tracking where needed.

Alerts start suspended. For a scheduled alert, use EXECUTE ALERT for a one-off evaluation and inspect history. Resume it only if you want periodic runs. Suspend it and then drop it after testing. Choose one writer per incident key for the simple outbox pattern. A regular Snowflake table does not enforce uniqueness just because a primary key was declared.

SQL · configuration template
GRANT EXECUTE ALERT ON ACCOUNT TO ROLE MAPLE_ALERT_OWNER;
GRANT USAGE ON DATABASE LS_M20_OPS_LAB TO ROLE MAPLE_ALERT_OWNER;
GRANT USAGE ON SCHEMA LS_M20_OPS_LAB.OPS TO ROLE MAPLE_ALERT_OWNER;
GRANT CREATE ALERT ON SCHEMA LS_M20_OPS_LAB.OPS TO ROLE MAPLE_ALERT_OWNER;
GRANT USAGE ON WAREHOUSE MAPLE_WH TO ROLE MAPLE_ALERT_OWNER;
GRANT SELECT ON TABLE LS_M20_OPS_LAB.OPS.EXPECTED_BATCHES TO ROLE MAPLE_ALERT_OWNER;
GRANT SELECT ON TABLE LS_M20_OPS_LAB.OPS.BATCH_AUDIT TO ROLE MAPLE_ALERT_OWNER;
GRANT SELECT, INSERT ON TABLE LS_M20_OPS_LAB.OPS.ALERT_OUTBOX TO ROLE MAPLE_ALERT_OWNER;

Check late batches without sending a message

The capstone creates EXPECTED_BATCHES, BATCH_AUDIT and ALERT_OUTBOX. Grant SELECT on the first two and SELECT and INSERT on the outbox to the alert owner. The condition looks for an expected batch whose due time has passed and which lacks a successful publication. The MERGE inserts one row per batch and alert type. The action repeats the check to avoid enqueuing a batch that got fixed between evaluation and action.

The capstone’s B102 due time is already past when you manually execute this test. The template uses UTC timestamps from the fixtures. Run the condition by itself when debugging a false result. Schedule and system load can affect how quickly alert evaluation runs. After recovery, close or mark the existing outbox row resolved in the incident process so it is not delivered as a new incident.

Expected outbox when B101 is published and B102 is overdue
BATCH_IDALERT_TYPE
B102DELIVERY_LATE
SQL · configuration template
USE SCHEMA LS_M20_OPS_LAB.OPS;

CREATE ALERT LATE_SALES
  WAREHOUSE = MAPLE_WH
  SCHEDULE = '5 MINUTE'
  IF (EXISTS (
    SELECT 1 FROM LS_M20_OPS_LAB.OPS.EXPECTED_BATCHES AS e
    WHERE e.due_at <= CURRENT_TIMESTAMP()
      AND NOT EXISTS (
        SELECT 1 FROM LS_M20_OPS_LAB.OPS.BATCH_AUDIT AS a
        WHERE a.batch_id = e.batch_id AND a.status = 'PUBLISHED'
      )
  ))
  THEN
    MERGE INTO LS_M20_OPS_LAB.OPS.ALERT_OUTBOX AS o
    USING (
      SELECT e.batch_id FROM LS_M20_OPS_LAB.OPS.EXPECTED_BATCHES AS e
      WHERE e.due_at <= CURRENT_TIMESTAMP()
        AND NOT EXISTS (
          SELECT 1 FROM LS_M20_OPS_LAB.OPS.BATCH_AUDIT AS a
          WHERE a.batch_id = e.batch_id AND a.status = 'PUBLISHED'
        )
    ) AS late
    ON o.batch_id = late.batch_id AND o.alert_type = 'DELIVERY_LATE'
    WHEN NOT MATCHED THEN INSERT (batch_id, alert_type, detected_at)
      VALUES (late.batch_id, 'DELIVERY_LATE', CURRENT_TIMESTAMP());

EXECUTE ALERT LATE_SALES;
-- Wait for history to show a completed run, then recheck.
SELECT batch_id, alert_type FROM ALERT_OUTBOX ORDER BY batch_id;

React to a new rejection record

The table owner enables change tracking first. If the alert uses a dedicated role, grant it SELECT on BATCH_AUDIT and INSERT on ALERT_OUTBOX. This example writes a fixed case marker only to show the condition and action. Run this in the scratch schema, resume it, and create a fresh REJECTED audit row through a new capstone attempt. For a real sender, carry the matching batch and attempt keys into the action using the documented condition query ID and RESULT_SCAN pattern, and deduplicate on that key.

Expected new data signal from a fresh rejecting attempt
BATCH_IDALERT_TYPE
LAB_SIGNALNEW_REJECTION
SQL · configuration template
-- As the table owner:
ALTER TABLE LS_M20_OPS_LAB.OPS.BATCH_AUDIT SET CHANGE_TRACKING = TRUE;
-- As the alert owner in the scratch schema:
CREATE ALERT NEW_SALES_REJECTION
  WAREHOUSE = MAPLE_WH
  IF (EXISTS (
    SELECT 1 FROM LS_M20_OPS_LAB.OPS.BATCH_AUDIT WHERE status = 'REJECTED'
  ))
  THEN INSERT INTO LS_M20_OPS_LAB.OPS.ALERT_OUTBOX (batch_id, alert_type, detected_at)
       VALUES ('LAB_SIGNAL', 'NEW_REJECTION', CURRENT_TIMESTAMP());

ALTER ALERT NEW_SALES_REJECTION RESUME;

Set up delivery and verify the result separately

Before wiring automated delivery, make one approved test call from the sender role. An administrator with CREATE INTEGRATION or CREATE NOTIFICATION INTEGRATION creates an email integration and limits the list to verified test-user addresses. The sender needs USAGE on the integration. For outbound machine-to-machine messages, configure a supported provider-specific integration and give the provider identity the required permission on the destination. Examples include AWS SNS, Azure Event Grid and Google Cloud Pub/Sub. Send a JSON message with APPLICATION_JSON and INTEGRATION only after the approved destination is configured.

The alert owner can inspect its alert history. Use a role authorized for the integration to read notification history. CONDITION_FALSE means the action did not need to run. ACTION_FAILED points to the SQL error in the action. TRIGGERED means the action ran successfully. A SUCCESS notification row indicates Snowflake considered it sent. It does not prove the recipient read it. For production, pass the incident key to the sender, keep retries bounded and deduplicate downstream. The queue action and message send are separate operations.

Representative outcomes to distinguish
Alert stateDelivery historyWhat to do
TRIGGEREDNo rowThe outbox action may have succeeded, but a sender has not called the integration.
TRIGGEREDSUCCESSConfirm the test recipient received and acknowledged the message.
ACTION_FAILEDNo rowRead SQL_ERROR_MESSAGE and verify the owner can write to the outbox.
SQL · configuration template
-- Replace with a verified, approved Snowflake test user email.
CREATE NOTIFICATION INTEGRATION MAPLE_TEST_EMAIL
  TYPE = EMAIL ENABLED = TRUE
  ALLOWED_RECIPIENTS = ('approved-operator@example.com');
GRANT USAGE ON INTEGRATION MAPLE_TEST_EMAIL TO ROLE MAPLE_ALERT_OWNER;

-- As the approved sender, after the outbox contains B102:
CALL SYSTEM$SEND_EMAIL('MAPLE_TEST_EMAIL', 'approved-operator@example.com',
  'Maple test: late B102', 'Test only. Review the B102 audit record.');

SELECT name, state, sql_error_message
FROM TABLE(LS_M20_OPS_LAB.INFORMATION_SCHEMA.ALERT_HISTORY(
  ALERT_NAME => 'LATE_SALES',
  SCHEDULED_TIME_RANGE_START => DATEADD('hour', -1, CURRENT_TIMESTAMP())
));

SELECT id, attempt, status
FROM TABLE(LS_M20_OPS_LAB.INFORMATION_SCHEMA.NOTIFICATION_HISTORY(
  INTEGRATION_NAME => 'MAPLE_TEST_EMAIL'
));

Configure a cloud destination and rehearse a failed delivery

For a full provider example, use a Snowflake account hosted on AWS and a dedicated standard Amazon SNS topic. The cloud operator creates the topic and a role with sns:Publish limited to that topic. The Snowflake integration administrator enters the topic and role Amazon Resource Names (ARNs). The SF_AWS_IAM_USER_ARN and SF_AWS_EXTERNAL_ID fields from DESCRIBE identify which Snowflake integration may assume that cloud role. The cloud operator adds those exact values to the role’s trust policy before the sender tests it. Use the linked provider guide and a controlled test subscription. For Azure Event Grid or Google Cloud Pub/Sub, choose the matching Snowflake integration and provider permission workflow.

To practise failed delivery offline, read the two representative attempts below. They share one notification ID. The first attempt got a retryable provider failure, and Snowflake queued another attempt. Do not enqueue a second message while the original is still being retried. Ask the provider owner to check permission and destination, confirm the latest state, and use the same stable case key if a final failure requires an approved resend. A test recipient should confirm that one case was received.

Simulated failure and recovery for one notification ID
IDAttemptStateOperator decision
notify-b1021RETRIABLE_FAILURECheck provider access. Do not create a duplicate send while retry is underway.
notify-b1022SUCCESSVerify one test case arrived and save the delivery evidence.
SQL · configuration template
CREATE NOTIFICATION INTEGRATION MAPLE_TEST_SNS
  ENABLED = TRUE TYPE = QUEUE DIRECTION = OUTBOUND NOTIFICATION_PROVIDER = AWS_SNS
  AWS_SNS_TOPIC_ARN = 'arn:aws:sns:us-east-2:111122223333:maple-test'
  AWS_SNS_ROLE_ARN = 'arn:aws:iam::111122223333:role/maple-test-publisher';
DESCRIBE NOTIFICATION INTEGRATION MAPLE_TEST_SNS;
GRANT USAGE ON INTEGRATION MAPLE_TEST_SNS TO ROLE MAPLE_ALERT_OWNER;

-- Run only after the AWS operator applies the role trust and test subscription.
CALL SYSTEM$SEND_SNOWFLAKE_NOTIFICATION(
  SNOWFLAKE.NOTIFICATION.APPLICATION_JSON('{"case_id":"B102:DELIVERY_LATE","test":true}'),
  SNOWFLAKE.NOTIFICATION.INTEGRATION('MAPLE_TEST_SNS')
);

Interview practice

Explain the decision and the evidence you would use to test it.

Beginner · Why does a new-data alert miss an empty feed?

It waits for new input. An empty feed produces no row to evaluate, so I use a scheduled check against the expected delivery list.

SQL · How do you avoid inserting the same alert every five minutes?

I use a MERGE keyed by the batch and alert type, with one writer for the lab. In production the sender also needs a stable deduplication key.

Production · When would you alert on costs?

I use completed metering windows with known delay to watch anomalies, and Snowflake’s cost controls where appropriate. An alert based on delayed usage cannot guarantee an immediate spend limit.

Words used in this lesson
Alert condition
SQL that checks whether a situation exists.
Alert action
SQL that runs when the condition is true.
Notification integration
A Snowflake object that configures an approved destination and how to reach it.
Outbox
A table of messages ready for a separate sender to process.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

Use the SQL and expected outputs in the sections above.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Maple Market is fictional. Output tables are representative. Live commands require an authorized test account and the roles, compute and edition listed in each lesson.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Which alert can detect that no new delivery arrived by the deadline?

Try it yourself

An alert history row says TRIGGERED, but nobody received a message. Where do you look?

Compare your reasoning

Confirm whether the action only queued the case. If a sender called a notification procedure, examine its integration history and the destination. Check the responder actually acknowledged the incident.

Connect this lesson to the learning path

Official sources and curriculum

Module 20 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab