Dagweave catalog

Run a SQL query and write results to S3 as CSV

sql-to-s3v1.1.2updated 2026-10-165 versions

Run a SQL query against a Postgres database and write the result set to Amazon S3 as a CSV object. Connection string and AWS credentials are read from Kubernetes Secrets.

Install v1.1.2

Installs the template into your Argo namespace. The URL is pinned to this version.

kubectl apply -n argo -f https://catalog.dagweave.com/api/v1/items/sql-to-s3/1.1.2/template.yaml

Or with the Argo CLI:

argo template create -n argo https://catalog.dagweave.com/api/v1/items/sql-to-s3/1.1.2/template.yaml

Facts

Category
Data
Tags
data python
Entrypoint
export
Template SHA-256
5314220cb0ee7c83587b6ac98c97897d7681e2a616d6b47c0a7088bd268df9c1
Source
sql-to-s3 at catalog commit 67458f7
API
item document, latest template.yaml

Images and provenance

Every image is pinned by digest, so a rebuilt tag can never change what this version runs.

RepositoryTagDigest
pythonnone recordedsha256:94d3426f1def7db4a106a232ac121bfd975393e5dfd40a619b955fae45fe7913

Parameters

NameDescriptionDefault
bucket required Target S3 bucket for the CSV result (no s3:// prefix).
Example my-data-bucket
none
key required Destination object key for the CSV result.
Example exports/users.csv
none
query required SQL query to run against the Postgres database.
Example SELECT id, email FROM users WHERE active
none
aws-access-key-id-key Key within the Secret that holds the AWS access key id. access-key-id
aws-secret-access-key-key Key within the Secret that holds the AWS secret access key. secret-access-key
aws-secret-name Name of the Kubernetes Secret in the run namespace holding the AWS credentials. aws-credentials
db-secret-key Key within the Secret that holds the Postgres connection string. connection-string
db-secret-name Name of the Kubernetes Secret holding the Postgres connection string (DSN / libpq URL). postgres-credentials
region AWS region of the bucket. us-east-1

WorkflowTemplate

Download template.yaml

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: sql-to-s3
  labels:
    dagweave.io/catalog-item: sql-to-s3
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.1.2"
    dagweave.io/catalog-category: "Data"
spec:
  entrypoint: export
  templates:
    - name: export
      inputs:
        parameters:
          # SQL query to run against the Postgres database.
          - name: query
          # Target S3 bucket and key for the CSV result (no s3:// prefix on bucket).
          - name: bucket
          - name: key
          # AWS region of the bucket.
          - name: region
            default: us-east-1
          # Name of the Kubernetes Secret holding the Postgres connection string
          # (DSN / libpq URL), plus the key within it.
          - name: db-secret-name
            default: postgres-credentials
          - name: db-secret-key
            default: connection-string
          # Name of the Kubernetes Secret holding the AWS credentials, plus the keys
          # within it. Defaults let a user leave them blank in the Inspector.
          - name: aws-secret-name
            default: aws-credentials
          - name: aws-access-key-id-key
            default: access-key-id
          - name: aws-secret-access-key-key
            default: secret-access-key
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # python:3.15-slim
        #
        # The one item in the catalog whose base cannot run it: it needs a Postgres
        # driver and an S3 client, and this image has neither, so both are installed
        # at run time from PyPI. Pinned versions, because a digest that freezes the
        # image while the code inside it floats is a digest that promises nothing.
        # ./Dockerfile is where that install belongs and where it goes once
        # ghcr.io/dagweave/catalog/sql-to-s3 is published and public; keep the two
        # version pins in step until then. See docs/adr/0001.
        image: python@sha256:94d3426f1def7db4a106a232ac121bfd975393e5dfd40a619b955fae45fe7913
        command: [sh, -c]
        # The quoted heredoc (<<'PY') passes the program to python literally — no
        # shell expansion — and every user value (query, bucket, key, credentials)
        # is read from an env var via os.environ, never interpolated into code.
        args:
          - |
            set -eu
            pip install --quiet --no-cache-dir psycopg2-binary==2.9.13 boto3==1.43.68
            python - <<'PY'
            import os, csv, io, boto3, psycopg2
            conn = psycopg2.connect(os.environ["DATABASE_DSN"])
            cur = conn.cursor()
            cur.execute(os.environ["SQL_QUERY"])
            buf = io.StringIO()
            w = csv.writer(buf)
            if cur.description:
                w.writerow([d[0] for d in cur.description])
                for row in cur:
                    w.writerow(row)
            cur.close()
            conn.close()
            body = buf.getvalue().encode("utf-8")
            boto3.client("s3").put_object(
                Bucket=os.environ["S3_BUCKET"],
                Key=os.environ["S3_KEY"],
                Body=body,
            )
            print("OK: wrote %d bytes to s3://%s/%s" % (
                len(body), os.environ["S3_BUCKET"], os.environ["S3_KEY"]))
            PY
        env:
          - name: SQL_QUERY
            value: "{{inputs.parameters.query}}"
          - name: S3_BUCKET
            value: "{{inputs.parameters.bucket}}"
          - name: S3_KEY
            value: "{{inputs.parameters.key}}"
          - name: AWS_DEFAULT_REGION
            value: "{{inputs.parameters.region}}"
          - name: DATABASE_DSN
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.db-secret-name}}"
                key: "{{inputs.parameters.db-secret-key}}"
          - name: AWS_ACCESS_KEY_ID
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.aws-secret-name}}"
                key: "{{inputs.parameters.aws-access-key-id-key}}"
          - name: AWS_SECRET_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.aws-secret-name}}"
                key: "{{inputs.parameters.aws-secret-access-key-key}}"

Version history

Read from the item's changelog. Each version has its own JSON document; the pinned catalogue vendors the manifest of the latest one, so that is the version that installs.

  1. 1.1.2 latest 2026-10-16

    Repin python on 3.15-slim and move psycopg2-binary 2.9.12 to 2.9.13, the first release with CPython 3.15 wheels. 2.9.12 had none, so pip fell back to building it from source and failed for want of pg_config.

    kubectl apply -n argo -f https://catalog.dagweave.com/api/v1/items/sql-to-s3/1.1.2/template.yaml
    argo template create -n argo https://catalog.dagweave.com/api/v1/items/sql-to-s3/1.1.2/template.yaml

    version document, template.yaml

  2. 1.1.1 2026-08-18

    Repin python:3.13-slim on the current digest, in ./Dockerfile as well as here. Same tag, CPython 3.13.14 to 3.13.15, and Entrypoint, Cmd, User and WorkingDir are identical on both. The repin clears nothing: util-linux CVE-2026-53615 is on the new bytes too. What it buys is a record that holds, because an OS baseline covers a pin only while that pin is its tag's head, and this one had fallen behind. pip also moves 26.1.2 to 26.2.1, which ships an SBOM of its vendored tree, so trivy now reports the msgpack and setuptools the old pin already vendored without declaring; both are recorded in hack/image-cve-exceptions.txt. This is the one item that runs pip, and it runs it with --no-cache-dir, which is the cache msgpack serialises. psycopg2-binary 2.9.12 and boto3 1.43.68 both resolve to wheels on this interpreter, so no sdist build runs either.

    This release is documented, but its manifest is not vendored here, so it has no install command. Version document

  3. 1.1.0 2026-08-12

    Cut ahead of the first image push: build-item-images reads the tag it pushes out of this file, so the version has to move before the dispatch or the first tag names the release that installs psycopg2-binary and boto3 from PyPI on every run. The template still does that install. It moves onto the image, and this entry gets the digest, once the package exists and is public.

    This release is documented, but its manifest is not vendored here, so it has no install command. Version document

  4. 1.0.1 2026-08-11

    Pin psycopg2-binary to 2.9.12 and boto3 to 1.43.68 in the run-time install. They floated, so the digest froze the image and not the code that ran in it.

    This release is documented, but its manifest is not vendored here, so it has no install command. Version document

  5. 1.0.0 2026-07-16

    Initial release.

    This release is documented, but its manifest is not vendored here, so it has no install command. Version document

Run it once

After installing, from the command line.

argo submit -n argo --from workflowtemplate/sql-to-s3 \
  -p bucket=my-data-bucket \
  -p key=exports/users.csv \
  -p query='SELECT id, email FROM users WHERE active'

Workflow that references it

A Workflow with the required parameters filled from the examples.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: sql-to-s3-
spec:
  workflowTemplateRef:
    name: sql-to-s3
  arguments:
    parameters:
      - name: bucket
        value: "my-data-bucket"
      - name: key
        value: "exports/users.csv"
      - name: query
        value: "SELECT id, email FROM users WHERE active"

As a step of a larger workflow

steps:
  - - name: sql-to-s3
      templateRef:
        name: sql-to-s3
        template: export