6.2 Step Functions Orchestration & Human-in-the-Loop Workflows

Key Takeaways

  • AWS Step Functions provides an optimized service integration (arn:aws:states:::bedrock:invokeModel) that invokes Amazon Bedrock models directly without requiring intermediate AWS Lambda compute layers.
  • The Step Functions Distributed Map state bounds simultaneous work with MaxConcurrency; RPM or token-rate limits still require measured pacing, retries, or a separate rate-control mechanism.
  • Production-grade GenAI state machines implement ASL Retry blocks with exponential backoff and jitter targeting Bedrock.ThrottlingException and Bedrock.ModelTimeoutException, paired with Catch blocks for graceful model fallback.
  • Human-in-the-loop (HITL) workflows leverage the .waitForTaskToken callback pattern, pausing execution indefinitely (up to 1 year) until an external reviewer returns a Task Token via SendTaskSuccess or SendTaskFailure.
  • Standard Workflows are mandatory for human-in-the-loop workflows because they support the .waitForTaskToken callback pattern and extended execution durations, whereas Express Workflows have a 5-minute maximum runtime and do not support task tokens.
Last updated: September 2026

6.2 Step Functions Orchestration & Human-in-the-Loop Workflows

This independent study guide by OpenExamPrep helps candidates prepare for the AWS Certified Generative AI Developer - Professional (AIP-C01) examination. While Amazon Bedrock Prompt Flows provides low-code visual orchestration for model-centric graphs, enterprise architectures often demand broader workflow orchestration spanning dozens of AWS services, complex distributed transactions, parallel batch operations across petabytes of data, and asynchronous human intervention.

AWS Step Functions serves as the enterprise-grade orchestration backbone for these advanced architectures. Through native optimized service integrations, sophisticated error-handling primitives, and callback task token patterns, Step Functions coordinates resilient generative AI pipelines that adhere to enterprise reliability and compliance standards.


Native Bedrock Optimized Service Integration

Step Functions provides an optimized task integration for Amazon Bedrock (arn:aws:states:::bedrock:invokeModel), eliminating the need to write and maintain intermediate AWS Lambda functions simply to invoke foundation models.

Key Capabilities & Mechanics

  • Zero Compute Overhead: Step Functions directly calls the Bedrock runtime API data plane, serializing request parameters and parsing response bodies natively within the state machine engine.
  • IAM Execution Role: The Step Functions state machine execution role must be granted permissions for bedrock:InvokeModel on the specific model ARN (e.g., arn:aws:bedrock:*::foundation-model/anthropic.claude-3-5-sonnet-* or Amazon Nova models).
  • Payload Construction & Intrinsic Functions: Using Amazon States Language (ASL), developers construct dynamic JSON payloads using intrinsic functions such as States.Format, States.StringToJson, and States.JsonToString to merge contextual variables into the model prompt.
  • Output Path Filtering: The response payload returned by Bedrock is mapped directly to the state output using JSONPath ($.Body.content[0].text for Anthropic Claude or $.Body.generation for Titan).

High-Throughput Batch Processing with Distributed Map

Enterprise generative AI workloads frequently require batch processing across large document corpora—such as analyzing historical call center transcripts, re-indexing compliance documents, or categorizing product catalogs. Step Functions features the Distributed Map state, capable of coordinating up to 10,000 concurrent parallel workflow executions.

[Amazon S3 Bucket (100,000 Documents)]
                  │
                  ▼
┌─────────────────────────────────────────────────────┐
│ Step Functions Distributed Map State                │
│  - ItemReader: S3 ListBucket / CSV / JSON           │
│  - MaxConcurrency: 500 (Bounds Concurrent Work)      │
│  - ItemBatcher: Groups 5 documents per worker       │
│                                                     │
│   ┌───────────────┐ ┌───────────────┐ ┌───────────┐ │
│   │ Child Exec 1  │ │ Child Exec 2  │ │ Child 500 │ │
│   │ Bedrock Model │ │ Bedrock Model │ │ ...       │ │
│   └───────────────┘ └───────────────┘ └───────────┘ │
│                                                     │
│  - ResultWriter: Direct Output to Amazon S3         │
└─────────────────────────────────────────────────────┘

Critical Distributed Map Parameters for Bedrock:

  1. ItemReader: Direct ingestion from Amazon S3. Step Functions reads S3 inventory files, CSVs, or JSON arrays without loading the dataset into memory.
  2. MaxConcurrency (Concurrency Protection): Uncontrolled parallel invocations can saturate Amazon Bedrock quotas and trigger ThrottlingException errors. Setting MaxConcurrency bounds simultaneous child work. To enforce Requests Per Minute (RPM) or Tokens Per Minute (TPM), also use measured task duration, retries, and explicit pacing or admission control; concurrency is not a rate.
  3. ItemBatcher: Combines multiple S3 items into a single child execution payload, enabling multi-document prompt batching to maximize model throughput and minimize per-invocation network overhead.
  4. ResultWriter: Streams child execution results directly to an Amazon S3 destination bucket, avoiding the Step Functions execution history limit (25,000 events or 4 MB payload size).

Resilient Error Handling: Retry, Backoff, Jitter & Fallbacks

In production generative AI pipelines, transient network issues, regional capacity spikes, and token rate limits are inevitable. Resilient ASL definitions employ structured Retry and Catch blocks:

ASL Retry Configuration for Bedrock

"Retry": [
  {
    "ErrorEquals": [
      "Bedrock.ThrottlingException",
      "Bedrock.ModelTimeoutException",
      "States.Timeout"
    ],
    "IntervalSeconds": 2,
    "MaxAttempts": 5,
    "BackoffRate": 2.0,
    "JitterStrategy": "FULL"
  }
]
  • Exponential Backoff (BackoffRate: 2.0): Successive retries wait exponentially longer (e.g., 2s, 4s, 8s, 16s, 32s) to allow downstream Bedrock rate limits to recover.
  • Full Jitter (JitterStrategy: FULL): Randomizes the retry delay between 0 and the calculated exponential interval. This prevents the "thundering herd" problem where hundreds of concurrent executions retry simultaneously and re-throttle the endpoint.

ASL Catch Configuration & Graceful Model Fallback

When retry attempts are exhausted, a Catch block redirects execution to an alternative fallback branch rather than failing the workflow:

  • Model Fallback: If the primary frontier model (e.g., Claude 3.5 Sonnet) remains throttled or unavailable, the Catch block transitions to a secondary state invoking a smaller, high-throughput model (e.g., Claude 3 Haiku or Amazon Nova Lite).
  • Dead-Letter Queue (DLQ): Unrecoverable errors are routed to an Amazon SQS DLQ or an Amazon SNS notification topic with the failed document ID and error payload for administrative triage.

Human-in-the-Loop (HITL) Architectures with .waitForTaskToken

Certain generative AI tasks—such as approving medical diagnostic summaries, issuing financial advice, or validating legal settlement offers—cannot be fully automated due to regulatory mandates. Step Functions implements the Task Token callback pattern to seamlessly pause workflow execution until a human reviewer renders a judgment.

The Task Token Callback Workflow

  1. Pause & Token Generation: A Task state specifies the .waitForTaskToken resource suffix (e.g., arn:aws:states:::sns:publish.waitForTaskToken or arn:aws:states:::sqs:sendMessage.waitForTaskToken).
  2. Context Injection: The state machine injects the contextual task token ($$.Task.Token) into the notification payload sent to human reviewers (via Amazon SNS email, an internal Slack bot, or an internal review web portal backed by Amazon SQS and DynamoDB).
  3. Indefinite Pause: Step Functions pauses execution of the state machine. Standard Workflows can maintain this paused state for up to 1 year with zero compute charges while waiting.
  4. External Evaluation & Resumption:
    • If the human reviewer approves the generated text: An external microservice invokes the Step Functions runtime API SendTaskSuccess(taskToken, outputPayload). Execution resumes immediately with the reviewer's modifications.
    • If the human reviewer rejects the generation: The microservice calls SendTaskFailure(taskToken, error, cause), triggering the state machine's Catch block to handle rejection logic.
  5. Heartbeat Protection: To prevent orphaned executions if a reviewer abandons a task, configure HeartbeatSeconds alongside TimeoutSeconds. If SendTaskHeartbeat is not received within the heartbeat window, Step Functions fails the task and escalates to a backup reviewer.

Standard vs. Express Workflows for Generative AI

Selecting the correct Step Functions workflow type is a frequent AIP-C01 exam topic:

FeatureStandard WorkflowsExpress Workflows
Maximum DurationUp to 1 yearUp to 5 minutes
Execution ModelExactly-once state transitionsAt-least-once (asynchronous) or At-most-once (synchronous)
Task Token Support (.waitForTaskToken)Fully supported (mandatory for HITL)Not supported
Distributed Map SupportFully supportedLimited to inline map
Pricing ModelBilled per state transitionBilled per execution duration and memory consumed
AuditabilityVisual execution history stored up to 90 daysExecution logs sent to Amazon CloudWatch Logs
GenAI Exam RecommendationMandatory for HITL, long batch RAG pipelines, and Distributed MapBest for high-volume, low-latency microservice tasks (< 5 min)

Concrete ASL State Machine Definition

The following Amazon States Language snippet illustrates a production Bedrock invocation with retry, model fallback, and human-in-the-loop task token review:

{
  "Comment": "AIP-C01 Production GenAI Workflow with Retry, Fallback, and HITL",
  "StartAt": "InvokePrimaryBedrockModel",
  "States": {
    "InvokePrimaryBedrockModel": {
      "Type": "Task",
      "Resource": "arn:aws:states:::bedrock:invokeModel",
      "Parameters": {
        "ModelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
        "Body": {
          "anthropic_version": "bedrock-2023-05-31",
          "max_tokens": 2000,
          "messages": [
            {
              "role": "user",
              "content": "Analyze this financial statement and summarize risk factors: ."
            }
          ]
        }
      },
      "ResultPath": "$.ModelResult",
      "Retry": [
        {
          "ErrorEquals": ["Bedrock.ThrottlingException", "Bedrock.ModelTimeoutException"],
          "IntervalSeconds": 2,
          "MaxAttempts": 4,
          "BackoffRate": 2.0,
          "JitterStrategy": "FULL"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": ["States.ALL"],
          "ResultPath": "$.FallbackError",
          "Next": "InvokeFallbackBedrockModel"
        }
      ],
      "Next": "HumanReviewStep"
    },
    "InvokeFallbackBedrockModel": {
      "Type": "Task",
      "Resource": "arn:aws:states:::bedrock:invokeModel",
      "Parameters": {
        "ModelId": "anthropic.claude-3-haiku-20240307-v1:0",
        "Body": {
          "anthropic_version": "bedrock-2023-05-31",
          "max_tokens": 2000,
          "messages": [
            {
              "role": "user",
              "content": "Analyze this financial statement and summarize risk factors: ."
            }
          ]
        }
      },
      "ResultPath": "$.ModelResult",
      "Next": "HumanReviewStep"
    },
    "HumanReviewStep": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sqs:sendMessage.waitForTaskToken",
      "Parameters": {
        "QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/ComplianceReviewQueue",
        "MessageBody": {
          "DocumentId.$": "$.DocumentId",
          "GeneratedSummary.$": "$.ModelResult.Body.content[0].text",
          "TaskToken.$": "$$.Task.Token"
        }
      },
      "TimeoutSeconds": 86400,
      "Next": "PublishApprovedSummary"
    },
    "PublishApprovedSummary": {
      "Type": "Pass",
      "End": true
    }
  }
}

Common Exam Traps & High-Stakes Scenarios

  • Trap: Using Express Workflows for Human Review. Express Workflows have a hard 5-minute timeout and do not support the .waitForTaskToken callback. Any human review workflow requires Standard Workflows.
  • Trap: Treating MaxConcurrency as RPM. Distributed Map needs a bounded concurrency chosen from load evidence, but rate quotas also require pacing, admission control, and bounded retries.
  • Trap: Intermediate Lambda for Simple Bedrock Invocations. Introducing an AWS Lambda function solely to execute bedrock.invoke_model() adds unnecessary latency, cold starts, cost, and maintenance. Step Functions optimized integration (arn:aws:states:::bedrock:invokeModel) is the recommended pattern.
Loading diagram...
Step Functions Human-in-the-Loop Architecture with Bedrock and Task Tokens
Test Your Knowledge

A legal technology enterprise must process 50,000 contracts from Amazon S3 and cap the number of simultaneously executing Bedrock tasks at 500. Which serverless architecture provides native S3 item reading, bounded parallelism, direct Bedrock integration, and S3 result writing?

A
B
C
D
Test Your Knowledge

A financial services firm generates automated investment summary reports using an Amazon Bedrock foundation model orchestrated by AWS Step Functions. Because the reports contain investment guidance, company compliance rules mandate that a certified financial compliance analyst must review and approve each report before it is emailed to clients. If the analyst rejects the report or suggests edits, the state machine must branch to an administrative review queue. The review process can take between 2 hours and 3 business days. How should the developer implement this review step in the Step Functions state machine?

A
B
C
D
Test Your Knowledge

An AI developer observes that during peak traffic hours, a Step Functions state machine invoking Amazon Bedrock frequently fails due to Bedrock.ThrottlingException errors. Additionally, during intermittent network spikes, model invocations occasionally experience Bedrock.ModelTimeoutException. The developer wants to make the state machine highly resilient against temporary spikes while ensuring that persistent failures switch to a secondary fallback model before failing the pipeline. Which ASL configuration achieves this requirement?

A
B
C
D