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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use lambda and step functions together to run multi-step cloud jobs. Step Functions tracks the workflow state while Lambda runs the task code. This pairing lets you build order processing, data pipelines, and alerts. One service manages the rules and retries, and the other runs short tasks. How lambda and step functions share roles and data Each workflow starts when an event triggers the state machine. The state machine reads its plan and calls the first function. It passes a small JS

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 lambda and step functions together to run multi-step cloud jobs. Step Functions tracks the workflow state while Lambda runs the task code.

This pairing lets you build order processing, data pipelines, and alerts. One service manages the rules and retries, and the other runs short tasks.

How lambda and step functions share roles and data

Each workflow starts when an event triggers the state machine. The state machine reads its plan and calls the first function.

It passes a small JSON payload as input to that function. The function runs its code and sends a JSON result back.

Step Functions saves that output and passes it to the next step. If a function fails, the state machine can wait and retry it.

This setup keeps retry logic out of your function code. Your functions stay small and do one clear job at a time.

Permissions flow through two separate cloud roles in this setup. First, the state machine needs a role that can call your functions.

Second, each function needs its own role to read databases or queues. Keeping these roles separate stops one bad step from breaking everything.

Common failure modes and how to scope roles

Many teams fail by giving every function one shared admin role. When one function has a bug, it can ruin all your tables.

Lambda Execution Roles + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You should give each function a tiny role with one job. A billing step should only write to the billing table.

Another common problem is passing huge data blobs between workflow steps. State machines have strict size limits for the JSON data they pass.

If a step makes a large file, save it to object storage. Then pass only the file path to the next function in line.

Teams also run into trouble with silent timeouts and double runs. A function might finish its database write right as the step times out.

The state machine then retries the step and writes the data twice. You can fix this by giving each request a unique ID.

Have your function check that ID before it writes any new records. Also set your step timeout lower than the function timeout limit.

Unlogged database queries during a workflow run create another big blind spot. When a function updates a database, logs often miss who started the job.

Pass a trace ID through every step and write it to your logs. Put database tasks in private networks with strict outbound traffic rules.

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

When should I call a function from another function instead?

Never chain functions by calling one directly from inside another function. You pay double for wait time and lose built-in retry tracking.

How do I handle sensitive data like card numbers in state payloads?

Do not pass raw card numbers, emails, or phone numbers in state payloads. Store sensitive records in a secure store and pass a lookup key, or apply data masking so it rewrites matched fields in results.

How should I set timeouts between the state machine and tasks?

Give each task step a clear timeout inside your state machine plan. Make that limit match the timeout on the function so hung jobs stop fast.

The query runs. The emails stay hidden.