The Simplest Way to Make Prefect and Step Functions Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair prefect and step functions to run Python data jobs alongside cloud state machines. Prefect manages dynamic Python tasks while AWS Step Functions coordinates native cloud services. Many engineering teams already own deep cloud workflows in AWS. They also want flexible Python scheduling for data and machine learning jobs. Putting both tools together lets each tool handle what it does best. You do not need to rewrite working cloud state machines in Python. You also do not need to force

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 prefect and step functions to run Python data jobs alongside cloud state machines. Prefect manages dynamic Python tasks while AWS Step Functions coordinates native cloud services.

Many engineering teams already own deep cloud workflows in AWS. They also want flexible Python scheduling for data and machine learning jobs. Putting both tools together lets each tool handle what it does best. You do not need to rewrite working cloud state machines in Python. You also do not need to force complex Python logic into JSON state definitions.

How prefect and step functions share roles and data

The link between these two tools starts with cloud identity and roles. A Prefect worker runs your Python code on a server or container. That worker needs an AWS role with permission to start a state machine. Or an AWS state machine step can call the Prefect API to start a flow.

Picking the caller depends on where your main schedule lives. If your data pipeline starts from Python events, let Prefect call AWS. The Prefect task sends a start request with a small JSON input payload. Then the worker checks the state machine status until the cloud run finishes. You can also use an event rule to alert Prefect when the job ends.

If AWS events start your workflow, let the state machine trigger Prefect. A cloud step sends an API request to start a specific Prefect deployment. Pass only small run IDs and storage paths between the two systems. Store large data sets in cloud object buckets instead of task payloads. Both tools have strict size limits on the JSON data they pass around.

Common failure modes and how to scope permissions

The biggest mistake teams make is sharing one broad cloud role across all workers. A single admin key on a Prefect worker exposes every state machine in your account. If one Python flow has a bug, it can trigger the wrong cloud job. Another common issue happens when teams store static cloud keys inside flow code. Static keys are hard to rotate and often leak in plain text logs.

Cloud Functions IAM + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Fix this by assigning a tight cloud role to each worker group. Give each worker permission to start and check only the state machines it needs. Use temporary role credentials from your cloud compute host instead of long-lived keys. When Step Functions calls Prefect, keep the API key in a secret store. Scope that key to a single workspace and limit what flows it can run.

Unlogged calls between the two tools also cause big headaches during outages. When a state machine fails, engineers waste hours matching AWS logs to Prefect runs. Always pass the Prefect flow run ID into the state machine input payload. Have the state machine return its own execution ID back to the Prefect log. This simple habit links both audit trails and makes fixing broken runs much faster.

When to split tasks between both workflow tools

Clear boundaries keep your system easy to read and fix over time. Use Step Functions when a job only touches native AWS services and queues. It excels at high-volume event routing and fast serverless tasks. Use Prefect when your team writes heavy data checks or custom Python code. Keeping a clear split prevents nested loops that are hard to trace and debug.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Should Prefect trigger Step Functions or the other way around?

Let Prefect trigger Step Functions when your main schedule depends on Python data pipelines. Let Step Functions trigger Prefect when cloud storage events or queues start the work.

How should we pass data between Prefect flows and AWS state machines?

Pass only small JSON metadata like file paths, run IDs, and date strings. Write large tables and files to cloud storage buckets and pass the bucket path.

How do we handle retries when both tools have retry rules?

Turn on retries in only one tool for any given step. Let Step Functions retry cloud service timeouts, and let Prefect handle high-level flow alerts.

The query runs. The emails stay hidden.