New to Kestra?
Use blueprints to kickstart your first workflows.
Trigger a DuckDB SQL anomaly check on every new S3 file with Kestra, then email a CSV of the flagged rows. Event-driven, declarative, no extra infra.
Catch bad data the moment it lands. This event-driven blueprint watches an Amazon S3 bucket and, whenever a new CSV file arrives, runs a DuckDB SQL query directly against the object in S3 to flag anomalous rows (for example, orders where price * quantity does not match the recorded total). Any flagged rows are exported to CSV and emailed to your data team automatically. It pairs DuckDB's fast, zero-copy SQL over object storage with Kestra's S3 file-event trigger so validation happens on arrival instead of on a nightly batch.
poll_for_new_s3_files trigger (io.kestra.plugin.aws.s3.Trigger) polls the bucket under source_prefix, picks up new files (filter: FILES), and MOVEs each one into destination_prefix, so a file is processed exactly once.query task (io.kestra.plugin.jdbc.duckdb.Queries) installs and loads the httpfs extension, sets S3 credentials, and runs read_csv_auto against the moved object to select rows that violate the data-quality rule. Results are stored via fetchType: STORE.csv task (io.kestra.plugin.serdes.csv.IonToCsv) converts the query results into a CSV file.if_anomalies_detected task (io.kestra.plugin.core.flow.If) checks outputs.query.size. When anomalies exist, send_email_alert (io.kestra.plugin.email.MailSend) sends an email with the anomalous rows attached as anomalies_in_orders.csv.DuckDB has no scheduler and no event listener of its own: it runs a query when you invoke it. Kestra fills that gap. The S3 trigger reacts to file events the moment data arrives, retries and timeouts make polling and queries resilient, every run is captured for full execution lineage, and the entire pipeline (trigger, SQL, conversion, conditional alert) is declared in one readable YAML file instead of glue scripts and cron.
AWS_DEFAULT_REGION: AWS region of the bucketAWS_ACCESS_KEY_ID: AWS access key used by the trigger and DuckDBAWS_SECRET_ACCESS_KEY: AWS secret key used by the trigger and DuckDBEMAIL_PASSWORD: password for the SMTP account sending alertsbucket, source_prefix, and destination_prefix variables to match your S3 layout.from, to, host, and port on send_email_alert.WHERE clause in the query task to encode your own data-quality rules.MOTHERDUCK_TOKEN secret and setting the DuckDB url to jdbc:duckdb:md:my_db?motherduck_token={{ secret('MOTHERDUCK_TOKEN') }}.