The Simplest Way to Make Airflow and Cloudformation Work Like They Should
Teams use airflow and cloudformation to build and run cloud jobs on a schedule. Airflow starts the workflow tasks, and CloudFormation builds the needed cloud stacks. This pair lets data teams spin up compute clusters only when jobs run. When the job ends, the workflow deletes the stack to save money. How airflow and cloudformation share roles and data Airflow uses built-in cloud operators to talk to the AWS API. The scheduler triggers a task that sends a template file to CloudFormation. Fir
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 use airflow and cloudformation to build and run cloud jobs on a schedule. Airflow starts the workflow tasks, and CloudFormation builds the needed cloud stacks.
This pair lets data teams spin up compute clusters only when jobs run. When the job ends, the workflow deletes the stack to save money.
How airflow and cloudformation share roles and data
Airflow uses built-in cloud operators to talk to the AWS API. The scheduler triggers a task that sends a template file to CloudFormation.
First, the worker node must log in to your AWS account. It uses an IAM role attached to the worker host or container.
Next, the task asks the AWS API to create or update a stack. CloudFormation reads the template and builds the compute nodes, buckets, or databases.
While the stack builds, an Airflow sensor checks the stack status. The sensor waits until all cloud parts are ready to do work.
CloudFormation then writes output values like host names or bucket names. Airflow reads those output values and passes them to the next task.
When the data work finishes, a final task calls CloudFormation again. That task deletes the temporary stack so idle servers do not waste budget.
Common failure modes in cloud stack workflows
Many teams give the Airflow worker one huge admin role. They do this so the worker can build any cloud resource.
A shared worker role creates a major security risk for your team. Every DAG on that worker gets the exact same broad cloud permissions.
If one bad task runs, it can delete production databases or buckets. Shared keys also make your cloud audit logs very hard to read.
CloudFormation Guard + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Every stack change looks like it came from the same worker machine. You cannot tell which team or workflow asked for the new stack.
Long-lived static keys stored in the Airflow database cause another big problem. Engineers often forget to rotate these keys, or they leak in task logs.
Network timeouts also break stack creation tasks during long runs. If a worker loses its network path, the task marks itself as failed.
Meanwhile, CloudFormation keeps building the stack in the background without any check. The next task retry then fails because the stack name already exists.
Scoping roles and network paths between both tools
You can fix the permission risk with a dedicated service role. Do not let the Airflow worker build the cloud resources by itself.
Instead, give the worker permission only to start a CloudFormation stack action. Then tell CloudFormation to assume a separate IAM role for the build.
Each workflow gets its own small stack role with strict rules. A data pipeline role can only create specific compute nodes and buckets.
You should also replace static AWS keys with short-lived role sessions. Attach an instance profile or task role directly to the Airflow worker.
Lock down the network path between your workers and the cloud API. Keep your workers in private subnets and use private VPC endpoints.
Traffic to the CloudFormation API will stay inside your private cloud network. Set up clear tags on every stack request from your DAG tasks.
Pass the DAG name and run ID as tags on the stack. This simple step links every cloud cost and audit log to one workflow.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Should Airflow build permanent cloud stacks or just temporary ones?
Use Airflow only for temporary stacks like batch compute clusters. Keep permanent databases and core networks in your main deployment pipeline instead.
How do I handle stack rollbacks when an Airflow task fails?
Use an Airflow sensor to watch the stack status until it finishes. Add a cleanup task that triggers on failure to delete broken stacks.
Where should I store the CloudFormation template files for my DAGs?
Store your template files in a versioned private object storage bucket. Have your Airflow task pass the bucket URL to the CloudFormation API.
Related guides
In this post