Execute a TASK triggered by AppFlow data integration to Snowflake

Execute a TASK triggered by AppFlow data integration to Snowflake

I tried out a method for automatically executing tasks using streams after linking Salesforce data to Snowflake with AppFlow. This article introduces a mechanism for detecting COPY INTO with Snowflake streams and kicking off tasks from there.
2026.07.07

This page has been translated by machine translation. View original

This is Suzuki from the Data Business Division.

Yesterday I published an article about trying out incremental data integration from Salesforce to Snowflake using Amazon AppFlow, and since I wanted to execute a TASK after the integration to run additional processing, I verified whether it could be triggered.

▼ Yesterday's published article

https://dev.classmethod.jp/articles/ingenst-data-salesforce2snowflake-with-incremental-amazon-appflow/

About the Implementation Approach

When combining AppFlow and Snowflake, I think there are broadly two methods for executing Snowflake processing triggered by data integration from AppFlow.

  1. Detect table changes on the Snowflake side using streams, and execute tasks
  2. Detect flow completion on the AWS side, and execute Snowflake processing from AWS

For the latter, one could consider triggering EventBridge to execute Lambda, for example, but since Snowflake's API cannot be called without holding Snowflake credentials on the AWS side, the former approach seems simpler.

Since Snowflake streams can detect COPY INTO operations on tables, it seemed possible to use this as a trigger to execute tasks.

https://docs.snowflake.com/ja/user-guide/streams-intro

For executing tasks from streams, I referenced the following and gave it a try.

https://dev.classmethod.jp/articles/snowflake-ai-extract-stream-task/

Trying It Out

1. Preparing Snowflake Resources

I created streams and tasks on the Snowflake side as shown below. The table monitored by the stream was created in a separate blog post, and I assumed that data is being integrated from Salesforce via an AppFlow flow.

-- Create stream
CREATE OR REPLACE STREAM OPPORTUNITY_STREAM ON TABLE APPFLOW_DB
.APPFLOW_SCHEMA.SALESFORCE_OPPORTUNITY;

-- Table for data consumption
CREATE OR REPLACE TABLE APPFLOW_DB.APPFLOW_SCHEMA.APPFLOW_LOAD_EVENTS (
  detected_at TIMESTAMP_NTZ,
  stream_row_count NUMBER
);

-- Task definition
CREATE OR REPLACE TASK APPFLOW_DB.APPFLOW_SCHEMA.CONSUME_OPPORTUNITY_STREAM
  WAREHOUSE = COMPUTE_WH
  WHEN SYSTEM$STREAM_HAS_DATA('APPFLOW_DB.APPFLOW_SCHEMA.OPPORTUNITY_STREAM')
AS
  INSERT INTO APPFLOW_DB.APPFLOW_SCHEMA.APPFLOW_LOAD_EVENTS
  SELECT
    CURRENT_TIMESTAMP(),
    COUNT(*)
  FROM APPFLOW_DB.APPFLOW_SCHEMA.OPPORTUNITY_STREAM;

-- RESUME the task
ALTER TASK CONSUME_OPPORTUNITY_STREAM RESUME;

2. Data Integration to Snowflake

I created data in Salesforce for verification purposes and integrated it into Snowflake via AppFlow.

▼ Example of created data

作成したデータ例

▼ Integration history in AppFlow

AppFlowでの連携履歴

3. Confirming Task Execution

Checking the task execution history, I confirmed that the INSERT had indeed been executed.

▼ Task execution history

タスクの実行履歴

▼ Executed task log

実行されたタスクログ

Closing

I used streams to execute a TASK triggered by AppFlow data integration into Snowflake.
This time I simply performed a SELECT on the data, but by chaining a task to execute a dbt project after this task, it could also serve as a trigger for dbt execution, which broadens the possibilities for pipeline construction.

https://docs.snowflake.com/ja/user-guide/tasks-graphs

I hope this was helpful.


Snowflakeの導入支援はクラスメソッドに!

クラスメソッドでは Snowflake の導入を支援しております。
製品の詳細や支援の内容についてお気軽にお問い合わせください。

Snowflakeの詳細を見る

Share this article

AWSのお困り事はクラスメソッドへ