Data Lake and Data Warehouse 7 min read

From Cron Jobs to Containers: Running Data Pipelines on AWS

The earlier articles in this series covered how to extract changes reliably, load them into Snowflake, and transform them with dbt. The last piece is how the steps run together in production. This is where many otherwise solid pipelines fall down.

The anti-pattern: separate schedules

A common setup runs the extraction script at 2:00 a.m. and dbt at 2:15 a.m., on the assumption that fifteen minutes is enough. It causes two kinds of problems:

  • Wasted spend. If extraction fails or finds nothing new, dbt still starts a Snowflake warehouse and processes an empty batch.
  • Partial loads. If extraction runs long because of a spike in changes, dbt starts while files are still being written and processes an incomplete batch.

The fix is to run the steps as one sequence: dbt starts only when extraction has finished successfully, and only if there is something new to process.

Option 1: A single wrapper script

If you aren’t ready to run a workflow platform, the simplest reliable approach is a small wrapper that runs extraction and then calls dbt.

# run_pipeline.py
import subprocess
import sys

from extract import run_extraction


def main() -> int:
    try:
        files_written = run_extraction()
    except Exception as exc:
        print(f"Extraction failed: {exc}", file=sys.stderr)
        # send an alert here (Slack, PagerDuty, SNS, ...)
        return 1

    if files_written == 0:
        print("No new changes; skipping dbt.")
        return 0

    # dbt build runs the models and their tests
    result = subprocess.run(["dbt", "build", "--select", "inventory"], cwd="dbt_project")
    if result.returncode != 0:
        print("dbt build failed", file=sys.stderr)
        return result.returncode

    print("Pipeline completed successfully.")
    return 0


if __name__ == "__main__":
    sys.exit(main())

The script exits with a non-zero code on any failure, so whatever runs it (a scheduler, a container platform or a CI job) can see the failure and raise an alert.

Option 2: A workflow orchestrator

When you have many tables, dependencies between pipelines, or a need for retries and run history, use an orchestrator such as Apache Airflow, Dagster or Prefect. The structure is the same, expressed as tasks with an explicit dependency:

# Conceptual Airflow DAG
extract = PythonOperator(
    task_id="extract_sql_server_to_s3",
    python_callable=run_extraction,
)

transform = BashOperator(
    task_id="dbt_build_inventory",
    bash_command="cd /app/dbt_project && dbt build --select inventory",
)

extract >> transform

For dbt specifically, there are dedicated integrations, such as the open-source Astronomer Cosmos package for Airflow and the native dbt support in Dagster, which show each dbt model as its own task. Third-party DbtRunOperator packages also exist; check that any you adopt is actively maintained.

Three rules that apply either way

  1. Fail fast. If extraction cannot connect or an upload fails, stop immediately with an error so transformation never runs on bad input.
  2. Clean up the landing zone. After a successful load, archive or remove processed files, or use COPY INTO ... PURGE = TRUE, so later runs don’t re-read old files.
  3. Advance the watermark last. Save the new watermark only after every file is confirmed in storage. A crash then means the next run repeats a range rather than skipping one.

Packaging the pipeline in a container

A single container image holding both the extraction code and the dbt project keeps the sequence together and makes every environment identical.

FROM python:3.11-slim-bookworm

# Microsoft ODBC Driver 18 for SQL Server
RUN apt-get update \
 && apt-get install -y --no-install-recommends curl gnupg ca-certificates unixodbc \
 && curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \
      | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \
 && echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" \
      > /etc/apt/sources.list.d/mssql-release.list \
 && apt-get update \
 && ACCEPT_EULA=Y apt-get install -y --no-install-recommends msodbcsql18 \
 && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY extract.py run_pipeline.py ./
COPY dbt_project/ ./dbt_project/

ENV DBT_PROFILES_DIR=/app/dbt_project

CMD ["python", "run_pipeline.py"]

requirements.txt lists pyodbc, pandas, pyarrow, boto3 and dbt-snowflake. Pin exact versions so builds are reproducible, and update them deliberately.

The dbt profile reads credentials from environment variables, so nothing secret is baked into the image:

# dbt_project/profiles.yml
snowflake_pipeline:
  target: prod
  outputs:
    prod:
      type: snowflake
      account: "{{ env_var('SNOWFLAKE_ACCOUNT') }}"
      user: "{{ env_var('SNOWFLAKE_USER') }}"
      password: "{{ env_var('SNOWFLAKE_PASSWORD') }}"
      role: TRANSFORMER
      warehouse: TRANSFORM_WH
      database: ANALYTICS
      schema: ANALYTICS

For production Snowflake service users, key-pair authentication is preferable to passwords; dbt-snowflake supports it through the same environment-variable approach.

Running it on AWS ECS Fargate

ECS Fargate runs containers without servers to manage, and you pay only while a task is running. That suits a batch pipeline that starts, works for a few minutes and stops.

Three settings matter most in the task definition:

  • Task IAM role for AWS access. Grant the task role permission to write to the landing bucket. boto3 picks up these credentials automatically, so no AWS keys go into the image or environment.
  • Secrets from AWS Secrets Manager or SSM Parameter Store. Map the SQL Server connection string and Snowflake credentials into the container through the task definition’s secrets section. They appear as ordinary environment variables at runtime and never appear in code or images.
  • Right-sized CPU and memory. Because extraction streams in chunks, memory needs stay modest. Start small and adjust from CloudWatch metrics.

Pattern A: Scheduled task (simplest)

Amazon EventBridge Scheduler starts the Fargate task on a schedule, for example hourly:

  1. EventBridge starts the task.
  2. The container runs run_pipeline.py: extraction first, then dbt build if there were changes.
  3. The container exits and you stop paying for it.

Because everything happens inside one task, there’s no gap between steps for things to go wrong.

Pattern B: Event-driven (decoupled)

Larger teams sometimes split extraction and transformation into separate containers that scale and deploy independently. In that case, the extraction task writes a small marker file (for example _SUCCESS or a manifest listing the files it wrote) as its final step. An S3 event notification on that marker triggers a Lambda function or an EventBridge rule, which starts the dbt task.

Triggering on a marker file rather than on every Parquet file is important: it guarantees dbt starts once per batch, and only after the whole batch is in place.

Summary

ConcernRecommendation
Step orderingOne sequence: extract, then transform only on success and only when there are changes
Small teamsWrapper script in a single container
Many pipelinesAirflow, Dagster or Prefect with explicit task dependencies
PackagingOne pinned, reproducible image with the ODBC driver and dbt
ComputeECS Fargate, paying only while the task runs
CredentialsTask IAM role for AWS; Secrets Manager for databases; key-pair auth for Snowflake
TriggeringEventBridge schedule, or an S3 marker-file event for decoupled tasks

Bringing the series together

Across six articles, we have built a pipeline that:

  • detects every change without gaps, using rowversion and MIN_ACTIVE_ROWVERSION();
  • extracts from very large tables without slowing production;
  • keeps a replayable history in a data lake landing zone;
  • applies changes in Snowflake without duplicates or stale overwrites;
  • keeps business logic in tested dbt models;
  • and runs securely and cheaply on AWS.

None of these steps is exotic, but getting all of them right at once is what separates a warehouse people trust from one they double-check in a spreadsheet.

Work with us

YenDigital designs and delivers data warehouse and data lake platforms on Snowflake and AWS, from architecture reviews to complete builds handed over to your team. If you’re planning a new platform or want a second opinion on the one you have, we’d be glad to talk.

Book a consultation

Share this article

Our Partners

Built with leading
AI technologies

We build and integrate AI solutions using technologies from OpenAI, Google Gemini, Anthropic, DeepSeek and Perplexity, selected to suit each client’s needs.

Enterprise-Ready AI Solutions Built for Scale & Security

Secure, scalable AI solutions designed to integrate with your enterprise systems and accelerate business outcomes.

Get a Quote