The Simplest Way to Make AWS CloudFormation and Airflow Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair aws cloudformation and airflow to build cloud resources and run daily jobs. CloudFormation sets up the cloud stacks, while Airflow runs tasks on a set schedule. This setup lets data teams spin up compute clusters only when jobs need them. Once the batch job finishes, the workflow tears the stack down to save money. You get repeatable cloud setups and clear task schedules in one flow. How aws cloudformation and airflow share roles and data Airflow needs a way to talk to Amazon Web

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair aws cloudformation and airflow to build cloud resources and run daily jobs. CloudFormation sets up the cloud stacks, while Airflow runs tasks on a set schedule.

This setup lets data teams spin up compute clusters only when jobs need them. Once the batch job finishes, the workflow tears the stack down to save money. You get repeatable cloud setups and clear task schedules in one flow.

How aws cloudformation and airflow share roles and data

Airflow needs a way to talk to Amazon Web Services during a task run. You give the Airflow worker an IAM role with clear rules. This role lets the worker call the CloudFormation API to build or remove stacks.

Data flows between the two tools through template inputs and stack outputs. Airflow sends input values when it asks CloudFormation to start a new stack. CloudFormation builds the databases, buckets, or compute nodes from that template.

While the stack builds, Airflow checks the stack status on a timer. It waits until the build finishes before it starts the next data task. If the stack fails to build, Airflow stops the pipeline and sends an alert.

When the stack is ready, CloudFormation shares output values like host names or bucket names. Airflow reads those outputs and passes them to the next task in the line. Then the worker runs queries or moves files using those new cloud parts.

Common failure modes and how to scope roles

Many teams fail because they give the Airflow worker one giant admin role. If one task has a bug, it can delete the wrong cloud stack. Shared keys also make it hard to see which user changed a resource.

Static keys stored inside Airflow variables create another big risk for your team. People copy these keys into logs or share them across different team setups. If a key leaks, an attacker can build costly servers in your account.

AWS IAM Policies + CloudFormation Guard: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, give Airflow a small role that only starts CloudFormation calls. Then attach a dedicated service role to each CloudFormation stack that you run. CloudFormation uses that service role to build the actual buckets or servers.

You should also lock down which templates each Airflow job can touch. Use tag rules and stack name prefixes to wall off each team. A marketing pipeline should never have the power to update a billing stack.

Network paths between the scheduler, the workers, and the cloud resources matter too. Keep your workers in private subnets and route API calls through private endpoints. Turn on cloud audit logs so you can trace every stack change back to a task.

Keeping template changes and task schedules in sync

Pipelines break when someone updates a template without checking the Airflow task inputs. If a template needs a new input value, the nightly run will fail. Store your templates and your workflow files in the same code repo.

Run a basic syntax check on both files before you merge any change. Test the stack build in a staging account before the real schedule runs. Good checks stop broken templates from halting your night batch jobs.

You also need a clear plan for stacks that get stuck during a rollback. Set timeouts on your Airflow wait tasks so workers do not hang all day. When a timeout hits, alert the on-call owner to check the failed stack events.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should Airflow build databases on every run or use existing stacks?

Use long-lived stacks for core databases that hold state every day. Let Airflow spin up and remove short-lived stacks for heavy compute clusters.

How do we stop two Airflow runs from changing the same stack?

Set your workflow to allow only one active run at a time. You can also add a unique run ID to each temporary stack name.

Where should we store database passwords created during a stack build?

Have your template save new passwords directly into a cloud secrets manager. Never pass raw passwords through stack outputs or plain Airflow task logs.

The query runs. The emails stay hidden.