Skip to main content
This guide walks through creating and running a simple AWS Step Functions state machine using the visual editor. You’ll build a workflow that simulates a camera system: when motion is detected, a Lambda determines whether the event is a threat and the state machine branches accordingly. What you’ll learn:
  • How to author a state machine in the Step Functions visual editor
  • Invoking Lambda functions from tasks
  • Using a Choice state to branch on task results
  • Inspecting execution inputs, outputs, and events for troubleshooting
  1. Open the Step Functions console and choose Create state machine.
A screenshot of the AWS Step Functions console showing two state machines with their names, types, creation dates and execution statistics, plus action buttons including "Create state machine." The left sidebar displays navigation and developer resources.
  1. Choose a template. For this demo use the Blank template so you can author the workflow from scratch.
A screenshot of the AWS console showing the Step Functions "Choose a template" dialog with multiple template cards (including a Blank template and examples like Distributed Map, Batch Job with Lambda, and API Gateway integrations). A left-hand sidebar lists use cases and services, and there are Select/Cancel buttons at the bottom.
  1. Familiarize yourself with the visual editor:
  • Canvas (center): Start → … → End
  • Left panel: actions and integrations (Lambda, SNS, SQS, ECS, etc.)
  • Right panel: properties for the selected state
Drag actions from the left onto the canvas and configure their properties on the right. We will build a tiny workflow with these steps:
  • Receive an event (camera/object identifier)
  • Invoke detect_threat Lambda to decide if the event is a threat
  • Branch: invoke threat_found if malicious, otherwise false_positive
I created the Lambda functions ahead of time; you can find them in the Lambda console.
Screenshot of the AWS Lambda console showing a list of four functions — detect_threat, false_positive, threat_found, and event_summary — all packaged as ZIPs using the Node.js 18.x runtime.
Lambda functions used in this demo
  1. Add the first Task: invoke the detect_threat Lambda
  • Drag an AWS Lambda Invoke task to the canvas.
  • Configure:
    • Name: Detect Threat (or similar)
    • Integration: optimized Lambda integration
    • Function: detect_threat
    • Payload: use state input as the task Payload (or filter using InputPath/Parameters)
    • Leave “Wait for callback” disabled for this demo
    • Set Next to the Choice state you’ll add next
    • Optionally add Retry and Catch handlers if desired
The canvas with the Detect Threat task will look like this:
A screenshot of the AWS Step Functions visual editor showing a simple state machine with a Lambda "Detect Threat" invoke between Start and End nodes. The left pane lists actions (AWS Lambda, SNS, ECS, etc.) and the right pane displays retry/error configuration for the Lambda.
You can configure Retry behavior (interval, attempts, backoff rate) and add Catchers to route errors to alternate states such as an error-notification Lambda.
A screenshot of the AWS Step Functions visual editor showing a simple state machine with a Lambda Invoke task labeled "Detect Threat" between Start and End. The left panel lists available actions (AWS services) and the right panel shows configuration for retriers and catchers.
Lambda function examples (Node.js) These are intentionally minimal implementations to illustrate data flow. detect_threat (Node.js):
threat_found (Node.js):
false_positive (Node.js):
  1. Add a Choice state to branch on the detect_threat result
  • Drag a Choice state from the Flow section and connect it after Detect Threat.
  • Create rules that inspect $.result.
Screenshot of the AWS Step Functions visual editor showing a state machine canvas with a Start node, a Lambda Invoke step labeled "Detect Threat," and a Choice state with two drop targets. The left sidebar lists workflow actions (Choice, Parallel, Map, Pass, Wait, Success, Fail) and the right pane shows Choice configuration.
Choice state rules:
  • Rule 1: $.result equals "THREAT" → route to Lambda threat_found
  • Rule 2: $.result equals "NO_THREAT" → route to Lambda false_positive
  • Optionally set a Default route for unexpected input
Example Choice conditions in Amazon States Language (ASL):
After saving rules and connecting branch targets, the visual layout will show Start → Detect Threat → Choice → Threat/NoThreat tasks → End.
A screenshot of the AWS Step Functions visual editor displaying a state machine: Start → Lambda "Detect Threat" → Choice that branches to "Threat Found" or "No Threat" Lambda tasks and then End. The left pane shows available actions (e.g., AWS Lambda Invoke, Amazon SNS Publish) and the right pane shows workflow properties.
Important: by default, the output of each state becomes the next state’s input. Use InputPath, Parameters, ResultPath, and OutputPath to select and shape the data passed between states for tighter control.
  1. Create the state machine
  • Click Create. Step Functions will offer to create an IAM execution role with permissions required by the states (for example, permissions to invoke Lambda and optionally X-Ray).
  • Inspect or refine the generated role if you need stricter least-privilege policies.
Step Functions can automatically create the execution role and attach the permissions required by the states you chose (for example, Lambda invocation and X‑Ray). Review and tighten the generated policy if your security posture requires least‑privilege access.
A confirmation dialog in the AWS Step Functions console showing that an execution role will be created, listing role permissions for AWS Lambda and AWS X‑Ray. Buttons at the bottom include "View role configuration" and an orange "Confirm" button.
The console validates retry and catcher configurations. Remove or fix any unused catchers or invalid error handlers before creating the state machine to avoid runtime surprises.
  1. Start executions and inspect runs
  • From the state machine details page choose Start execution and provide JSON input representing the event, for example:
  • Start the execution. The visual execution trace will color states as they run and show which branch was taken based on the detect_threat result.
  • Click any state in the execution trace to view input/output JSON, timestamps, duration, and any SDK responses.
Example Task definition captured in the state machine (shows Lambda invoke and retry config):
The Events pane shows the sequence of execution events (ExecutionStarted, TaskStateEntered, TaskStateStarted, TaskStateSucceeded, ChoiceStateEntered, etc.), with timestamps and state names to help with diagnostics.
A screenshot of the AWS Step Functions console showing the Events pane for a state machine execution. It lists event IDs and types (ExecutionStarted, TaskStateEntered/Started/Succeeded, ChoiceState), steps like "Detect Threat" and "No Threat", resource links to Lambda, and timestamps.
Run multiple executions — detect_threat is randomized here, so different runs will exercise both branches. You can review the list of executions and their statuses (Succeeded, Failed, Timed out, Aborted) from the State Machines list view.
A screenshot of the AWS Step Functions console showing a table of three state machines with their names, types, creation dates, statuses and execution counts, plus action buttons like "Create state machine." The left sidebar shows navigation links and developer resources.
Click a specific state machine to see execution history and run details for troubleshooting or auditing.
Screenshot of the AWS Step Functions console showing a state machine named "MyStateMachine-bd6inz729" with its ARN, IAM role, type (Standard, Active) and creation date. The executions pane below lists two finished runs, both marked Succeeded.
Summary — what this demo demonstrates:
  • Authoring a state machine with the Step Functions visual editor
  • Invoking Lambda functions from Task states
  • Using Choice states to branch based on task outputs
  • Inspecting inputs, outputs, and events to debug executions
Next steps and extensions:
  • Integrate other services: SNS, SES, DynamoDB, SQS, ECS
  • Add robust retry and Catch logic for production resiliency
  • Use Map or Parallel states for data-parallel or concurrent workflows
  • Tighten generated IAM roles for least-privilege access
Links and references:

Watch Video