Stop polling your S3 bucket with cron jobs. This lesson teaches you how to wire up Snowflake External Stages and Snowpipe to automatically load files into your warehouse within seconds of arrival — with no orchestration code required. You'll understand storage integrations, file formats, and pipe monitoring from the ground up.

Picture this: your company's e-commerce platform drops a new JSON file into an Amazon S3 bucket every five minutes — order events, clickstream data, inventory updates. Somewhere downstream, your analytics team is waiting on that data to show up in Snowflake so they can query it. The naive solution is a cron job that runs a COPY INTO command every hour. It works, but you're always 55 minutes stale at worst, and someone has to babysit it. When the cron job silently fails at 2am, nobody knows until a dashboard looks wrong the next morning.
This lesson is about the right solution: using Snowflake's native tooling — External Stages and Snowpipe — to build a continuous, event-driven loading pipeline that processes files as soon as they land in cloud storage. No polling loops, no brittle cron jobs, and no missing files. By the end of this lesson, you'll understand how data flows from a cloud storage bucket all the way into a queryable Snowflake table, automatically, with minimal operational overhead.
What you'll learn:
COPY INTO command that loads structured and semi-structured dataYou should be comfortable writing basic SQL and have access to a Snowflake account. If you haven't set one up yet, the guide on Setting Up Your First Cloud Data Warehouse: A Hands-On Guide to Snowflake or BigQuery Free Tier will get you there in under an hour. You should also have a general sense of what Snowflake is and why it exists — the Cloud Data Warehouses: Snowflake vs BigQuery vs Redshift comparison is a great primer.
You'll need either an AWS S3 bucket, an Azure Blob Storage container, or a GCS bucket to follow along with the hands-on portions. The examples here use S3, but the concepts translate directly.
Before data can be loaded into Snowflake, Snowflake needs to know where to look. That's what a Stage is: a named pointer to a location where data files live.
Snowflake supports two kinds of stages. An internal stage is storage that Snowflake manages itself — useful for ad hoc file uploads. An external stage points to storage you own and manage outside Snowflake: an S3 bucket, an Azure Blob container, or a GCS bucket. For any real pipeline, you'll be using external stages.
Think of an external stage the way you'd think of a bookmark in a browser. The bookmark doesn't copy the web page — it just remembers how to find it. Similarly, a stage doesn't pull data into Snowflake; it records the path, credentials, and format options needed to reach files in your cloud storage.
Key insight
Snowflake never proactively reads from your cloud storage on its own. The stage is passive — it's an address. What actually triggers loading is either a COPY INTO command (manual or scheduled) or Snowpipe responding to an event notification. This distinction matters a lot when troubleshooting.
Here's the anatomy of a CREATE STAGE command:
CREATE OR REPLACE STAGE raw.orders_stage
URL = 's3://your-company-data/orders/'
CREDENTIALS = (
AWS_KEY_ID = 'AKIA...'
AWS_SECRET_KEY = 'your-secret-key'
)
FILE_FORMAT = (
TYPE = 'JSON'
STRIP_OUTER_ARRAY = TRUE
);
Let's break this down:
URL — the S3 path prefix where your files will land. All files under this prefix are visible to the stage.CREDENTIALS — how Snowflake authenticates to your cloud storage. Using static access keys works but isn't ideal for production. A better approach is using a Storage Integration, which lets Snowflake assume an IAM role rather than holding long-lived credentials. We'll cover that shortly.FILE_FORMAT — tells Snowflake what kind of files to expect and how to parse them. You can specify this inline (as above) or reference a named File Format object.Warning
Never hardcode AWS access keys in your DDL scripts if you're storing them in version control. Use a Storage Integration or pull credentials from environment variables at runtime. Leaked keys in Git history are a real and common security incident.
A Storage Integration creates a trust relationship between Snowflake and your AWS IAM. Instead of Snowflake holding your credentials, AWS trusts Snowflake's identity, and you grant that identity permission to read your bucket.
CREATE OR REPLACE STORAGE INTEGRATION s3_orders_integration
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = 'S3'
ENABLED = TRUE
STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::123456789:role/snowflake-s3-access'
STORAGE_ALLOWED_LOCATIONS = ('s3://your-company-data/orders/');
After creating this, run DESC INTEGRATION s3_orders_integration; and copy the STORAGE_AWS_IAM_USER_ARN and STORAGE_AWS_EXTERNAL_ID values. You'll paste those into your IAM role's trust policy in AWS. This is a one-time setup step.
Then reference your integration in the stage:
CREATE OR REPLACE STAGE raw.orders_stage
URL = 's3://your-company-data/orders/'
STORAGE_INTEGRATION = s3_orders_integration
FILE_FORMAT = (
TYPE = 'JSON'
STRIP_OUTER_ARRAY = TRUE
);
If multiple stages and pipes will read JSON files with the same structure, extract the parsing rules into a named File Format:
CREATE OR REPLACE FILE FORMAT raw.json_format
TYPE = 'JSON'
STRIP_OUTER_ARRAY = TRUE
IGNORE_UTF8_ERRORS = FALSE
NULL_IF = ('NULL', 'null', '');
Then reference it:
CREATE OR REPLACE STAGE raw.orders_stage
URL = 's3://your-company-data/orders/'
STORAGE_INTEGRATION = s3_orders_integration
FILE_FORMAT = raw.json_format;
This makes changes easy. If your upstream producer starts wrapping JSON in an outer array and you need to toggle STRIP_OUTER_ARRAY, you change the file format once — not every stage definition.
Before we automate anything, understand how loading actually works: the COPY INTO command.
COPY INTO raw.orders
FROM @raw.orders_stage
PATTERN = '.*orders_2024.*\.json'
ON_ERROR = 'CONTINUE'
FORCE = FALSE;
What each piece does:
FROM @raw.orders_stage — the @ prefix tells Snowflake this is a stage name, not a table name. Snowflake lists the files at the stage's URL and prepares to load them.PATTERN — a regex that filters which files to load. Without this, Snowflake will try to load every file under the stage's URL prefix.ON_ERROR = 'CONTINUE' — if one row fails to parse, skip it and continue loading the rest. 'ABORT_STATEMENT' (the default) would roll back the entire file.FORCE = FALSE — the default and the safe choice. Snowflake tracks which files it has already loaded (in a metadata layer called the load history) and skips them. Setting FORCE = TRUE would re-load files you've already processed, creating duplicates.Tip
COPY INTO is idempotent by default because of the load history. Files already processed won't be loaded again unless you explicitly use FORCE = TRUE or the load history expires (it's retained for 64 days). This makes it safe to run COPY INTO repeatedly as a cron job without duplicating data — but Snowpipe is still a better solution for continuous loading.
For JSON, you often load the entire document into a single VARIANT column and let Snowflake's semi-structured query engine handle it:
CREATE OR REPLACE TABLE raw.orders (
load_timestamp TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP(),
raw_data VARIANT
);
COPY INTO raw.orders (raw_data)
FROM (SELECT $1 FROM @raw.orders_stage)
FILE_FORMAT = raw.json_format;
The $1 syntax refers to the first (and only) column in a JSON file — the entire parsed document. You can then use dot notation and colon notation to query fields: raw_data:order_id::STRING, raw_data:items[0]:sku::STRING, and so on.
This is a common pattern in ELT vs ETL pipelines: land raw JSON first, transform it with dbt afterwards.
Manual COPY INTO is fine for backfills and one-time loads, but it isn't continuous. You'd need something external — like Airflow — to schedule it, monitor it, and retry it. Snowpipe removes that need for the loading step itself.
Snowpipe is Snowflake's serverless, continuous data ingestion service. Instead of your code calling COPY INTO on a schedule, Snowpipe listens for notifications from your cloud storage and fires off micro-batch loads automatically whenever new files arrive.
The core concept is straightforward: when a file lands in S3, S3 sends an event notification to an SQS queue (or SNS topic). Snowpipe monitors that queue. When a message arrives saying "new file at s3://your-bucket/orders/2024/03/15/events.json," Snowpipe queues the file for loading and processes it, usually within 30–60 seconds.
Key insight
Snowpipe doesn't run on a Snowflake virtual warehouse — it uses a Snowflake-managed compute layer billed per second of active loading. This makes it economical for sporadic, unpredictable file arrival patterns. If you're loading files constantly at high volume, batch COPY INTO on a warehouse can actually be cheaper. For real-time vs batch decisions, latency requirements drive the choice.
A pipe is the Snowflake object that ties together a stage, a file format, and a target table, with Snowpipe semantics:
CREATE OR REPLACE PIPE raw.orders_pipe
AUTO_INGEST = TRUE
COMMENT = 'Loads order events from S3 as they arrive'
AS
COPY INTO raw.orders (raw_data)
FROM (SELECT $1 FROM @raw.orders_stage)
FILE_FORMAT = raw.json_format;
The critical piece here is AUTO_INGEST = TRUE. That's what enables event-driven loading. With AUTO_INGEST = FALSE, you'd have to call the Snowpipe REST API to trigger loads — useful if you're managing orchestration yourself, but most teams want the automatic version.
After creating the pipe, run:
SHOW PIPES;
Look for the notification_channel column. It contains an ARN for an SQS queue that Snowflake automatically provisioned. Copy that ARN — you'll need it in the next step.
In the AWS Console, navigate to your S3 bucket and open the Properties tab. Scroll down to Event Notifications and create a new one:
notification_channel aboveorders/ — highly recommended if multiple pipes share one bucketSave the configuration. Within a few minutes, any file dropped into that bucket path will trigger a notification, which Snowpipe picks up and processes.
Note
The SQS queue in the notification_channel is owned and managed by Snowflake. You don't create or pay for it — Snowflake provisions it as part of Snowpipe's infrastructure. You're simply wiring S3 to send notifications to it.
One of the common mistakes teams make is setting up Snowpipe, confirming the first few files load, and then assuming it'll run forever without attention. It won't. You need to monitor it.
SELECT SYSTEM$PIPE_STATUS('raw.orders_pipe');
This returns a JSON object with key fields:
executionState — RUNNING is what you want. PAUSED means nothing will load.pendingFileCount — files queued but not yet loadedlastIngestedTimestamp — when the most recent file was successfully loadednotificationChannelName — confirms which SQS queue is attachedSnowflake maintains a detailed record of every file Snowpipe has attempted to load:
SELECT
file_name,
last_load_time,
row_count,
error_count,
status
FROM TABLE(information_schema.copy_history(
TABLE_NAME => 'RAW.ORDERS',
START_TIME => DATEADD('hour', -24, CURRENT_TIMESTAMP())
))
ORDER BY last_load_time DESC;
Look for rows where status = 'LOAD_FAILED' or where error_count > 0. Those are your problem files.
Tip
Set up an Airflow DAG or a simple scheduled task that queries copy_history and alerts your team if error rates spike or if lastIngestedTimestamp goes stale for longer than your SLA. Snowpipe failing silently is exactly the problem you were trying to avoid by not using cron jobs.
If notifications were missed (say, S3 was misconfigured for a few hours and files piled up), you can tell Snowpipe to re-scan the stage and load any files it hasn't processed yet:
ALTER PIPE raw.orders_pipe REFRESH;
This triggers a manual scan of the stage's S3 path and queues unprocessed files. It's a safe operation because Snowpipe tracks load history and won't double-load files it already ingested.
Data in the real world is messy. Files will arrive malformed. Schema will drift. Producers will introduce new fields or break existing ones.
By default, Snowpipe uses ON_ERROR = 'CONTINUE' — it loads valid rows and skips bad ones. You can inspect rejected rows using the VALIDATE function after a manual COPY INTO, but for Snowpipe, you rely on copy_history to surface errors.
If error_count in copy_history is nonzero, the file was partially loaded. The errored rows are not in your table. You'll need to fix the source file and reload it manually using COPY INTO ... FORCE = TRUE, or handle the gap in a downstream transformation.
What if your upstream producer adds a new field to the JSON? If you're loading into a VARIANT column, this is handled automatically — JSON is schema-flexible by nature. The new field just appears on new records. Your dbt models downstream need to be written to handle optional fields gracefully.
If you're loading into a structured table with a fixed schema, Snowflake will reject rows where the file schema doesn't match the table schema. Consider using the MATCH_BY_COLUMN_NAME option and adding a VARIANT overflow column for future-proofing:
COPY INTO raw.orders_structured
FROM @raw.orders_stage
FILE_FORMAT = raw.json_format
MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE;
This maps file columns to table columns by name rather than position, which is more resilient to column reordering. For more robust handling of schema drift across producer and consumer boundaries, see the article on implementing data contracts between ingestion and transformation.
In this exercise, you'll set up an external stage, create a target table, load a sample JSON file manually, and then create a pipe. You'll simulate the full flow in a Snowflake free trial environment with a local file upload.
Step 1: Create a database and schema
CREATE DATABASE IF NOT EXISTS wsd_demo;
CREATE SCHEMA IF NOT EXISTS wsd_demo.raw;
USE SCHEMA wsd_demo.raw;
Step 2: Create a named file format
CREATE OR REPLACE FILE FORMAT json_newline
TYPE = 'JSON'
STRIP_OUTER_ARRAY = FALSE
IGNORE_UTF8_ERRORS = TRUE;
Step 3: Create an internal stage for local testing
CREATE OR REPLACE STAGE demo_stage
FILE_FORMAT = json_newline;
Step 4: Create a sample JSON file on your laptop
Save this as orders.json:
{"order_id": "ORD-001", "customer_id": "CUST-42", "total": 149.99, "status": "shipped", "ts": "2024-03-15T08:23:11Z"}
{"order_id": "ORD-002", "customer_id": "CUST-17", "total": 29.50, "status": "processing", "ts": "2024-03-15T08:31:04Z"}
{"order_id": "ORD-003", "customer_id": "CUST-99", "total": 599.00, "status": "shipped", "ts": "2024-03-15T08:44:55Z"}
Step 5: Upload the file using the Snowflake web UI
In Snowsight (Snowflake's web interface), navigate to Data → Databases → WSD_DEMO → RAW → Stages → DEMO_STAGE. Click the "Upload Files" button and upload orders.json.
Step 6: Create the target table
CREATE OR REPLACE TABLE wsd_demo.raw.orders (
load_ts TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP(),
raw_data VARIANT
);
Step 7: Load the file manually
COPY INTO wsd_demo.raw.orders (raw_data)
FROM (SELECT $1 FROM @demo_stage)
FILE_FORMAT = json_newline;
Step 8: Query the results
SELECT
raw_data:order_id::STRING AS order_id,
raw_data:customer_id::STRING AS customer_id,
raw_data:total::FLOAT AS total,
raw_data:status::STRING AS status,
raw_data:ts::TIMESTAMP_NTZ AS event_timestamp
FROM wsd_demo.raw.orders;
You should see three rows with properly typed columns. This is the foundation. For a production external stage, you'd swap the internal stage for an S3-backed stage with a storage integration, then add a pipe with AUTO_INGEST = TRUE.
Files aren't loading automatically
Check SYSTEM$PIPE_STATUS and confirm executionState = 'RUNNING'. If the pipe is paused (which can happen after too many consecutive errors), resume it with ALTER PIPE raw.orders_pipe SET PIPE_EXECUTION_PAUSED = FALSE. Then verify the S3 event notification is correctly pointed at the SQS ARN from notification_channel.
Duplicate rows appearing in the target table
You likely used FORCE = TRUE somewhere — either in a pipe's underlying COPY INTO definition (don't do this) or in a manual refresh. Snowpipe's deduplication window is load history–based, not content-based. If you need row-level deduplication, handle it in your dbt transformation layer with a ROW_NUMBER() deduplication pattern.
COPY INTO loads no rows and reports "files already loaded"
This is correct behavior — Snowflake's load history is preventing re-processing. If you genuinely need to reload a file (e.g., after fixing a schema bug), either use FORCE = TRUE or truncate the target table and re-run. Consider whether you actually need the data reloaded or whether fixing the downstream transformation is cleaner.
JSON parsing errors on valid-looking files
Check your file format's STRIP_OUTER_ARRAY setting. A file that is a single JSON array [{...}, {...}] needs STRIP_OUTER_ARRAY = TRUE. A newline-delimited JSON file (one object per line) does not. These two formats look similar but parse completely differently.
Stage can't access the S3 bucket
Run LIST @raw.orders_stage; and read the error message. Usually it's an IAM permission issue — the Snowflake IAM user or role doesn't have s3:GetObject and s3:ListBucket on the bucket. If using a Storage Integration, re-check that the trust policy in AWS references the correct STORAGE_AWS_IAM_USER_ARN and STORAGE_AWS_EXTERNAL_ID from DESC INTEGRATION.
Warning
Snowpipe has a file size limit of 250 MB per file and handles best with files between 100 MB and 250 MB for efficiency. Very small files (under 1 MB) are processed less efficiently because each file has fixed overhead. If your producer generates many tiny files, consider batching them into larger files upstream, or accept the overhead as the cost of near-real-time delivery.
You've now covered the full mental model for continuous data loading into Snowflake:
COPY INTO is the core loading command, idempotent by default via load history trackingCOPY INTO with event-driven triggering, processing files automatically as they arrive in S3SYSTEM$PIPE_STATUS and copy_history is not optional — silent failures are realThis foundation fits naturally into a broader modern data stack architecture. Files land in S3 from your application, Snowpipe ingests them into raw tables in Snowflake, and then dbt transforms those raw VARIANT columns into clean, structured models that analysts can query. That transformation layer is where the real data modeling work happens — and understanding how data warehouses physically store that data will help you design tables that query efficiently once they're loaded.
If you're designing the ingestion side of a larger pipeline, it's worth evaluating whether Snowpipe is the right tool or whether a managed connector from Fivetran or Airbyte better fits your source systems. Snowpipe excels when you control the files being written to S3. For SaaS sources, APIs, and databases, managed connectors tend to be a better fit.
For higher-volume, lower-latency use cases where Snowpipe's 30–60 second latency isn't enough, Snowflake Dynamic Tables and Kafka-based pipelines are the natural next step — the architecture behind that is covered in the article on designing a real-time ingestion pipeline with Kafka and Snowflake Dynamic Tables.