Lesson 1 of 5 Data Pipeline Orchestration

Orchestrating Pipelines with AWS Step Functions

This lesson explains how AWS Step Functions, the serverless orchestrator for pipelines that span many AWS services, runs steps in the right order, handles errors and retries, and shows what happened.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the state types of a state machine.
  • Distinguish request response, run a job and wait for callback integration patterns.
  • Handle errors with Retry and Catch and choose a workflow type.
  • Choose between Step Functions, Glue workflows and MWAA.

States

A Step Functions state machine is a workflow built from states. A Task state does the work by calling a service, such as starting a Glue job or invoking a Lambda function. A Choice state branches on the data, for example skipping a load when a file is empty. A Parallel state runs several branches at the same time and waits for all of them, and a Wait state pauses for a period or until a time.

A Map state runs the same steps for each item in a list. Its Distributed Map mode runs up to thousands of child workflows in parallel and can take its items directly from S3, so it can process millions of objects or the rows of a large CSV file. The following table summarises the state types.

StatePurpose
TaskCalls a service
ChoiceBranches
ParallelRuns branches at the same time
MapRuns steps for each item; Distributed Map handles millions of S3 objects or CSV rows
WaitPauses
Match the pairs

Step Functions states

Exam skills 1.3.1 · 3.1.1

Match each requirement with the Step Functions state.

Log in to try this activity Interactive activities are free with an account.

Integration patterns

A Task state can call a service in three ways, and the choice decides whether the workflow waits. With request response, the state calls the service and moves on as soon as the call returns. Starting a Glue job this way only confirms the job started, not that it finished. The .sync pattern, such as glue:startJobRun.sync, starts the job and waits until it completes, failing the state if the job fails. This is what a pipeline usually needs, and it works with EMR, EMR Serverless, Athena, ECS and SageMaker.

Wait for callback pauses the workflow and passes a task token to an external process, such as a person approving a change. The workflow continues only when that process returns the token. The following table summarises the patterns.

Integration patternBehaviour
Request responseCalls the service and moves on immediately
.sync (run a job)Starts a job and waits for it, for example glue:startJobRun.sync, EMR, EMR Serverless, Athena, ECS, SageMaker
Wait for callbackPauses until a task token is returned, for example for human approval

The following diagram compares what the workflow waits for with each integration pattern.

The three ways a Task state can call a service. With request response, the state moves on as soon as the Glue job has started. With .sync, it waits until the job completes and fails if the job fails. With wait for callback, the workflow pauses until an external process returns the task token.
Bar lengths are illustrative.
Scenario questions

Waiting for a job

Exam skills 1.3.1 · 3.1.1

Choose the Task integration pattern for each requirement.

Log in to try this activity Interactive activities are free with an account.

Error handling and workflow types

Step Functions handles errors declaratively in the workflow definition rather than in code. A Retry field on a state retries it on specified errors, with exponential backoff and a maximum number of attempts, which handles transient failures such as throttling. A Catch field routes errors that persist to another state, such as a clean-up step or a notification, so failures are handled rather than simply ending the workflow.

Step Functions offers two workflow types. Standard workflows run for up to a year, execute each step exactly once and keep a full execution history, which suits long-running data pipelines and processes with human approval. Express workflows run for up to five minutes, handle very high volumes of executions and cost less, which suits short, frequent processing such as handling individual events.

The following diagram shows a nightly Step Functions state machine and its error handling.

The nightly state machine. EventBridge Scheduler starts it at 02:00. A crawler runs, then a Parallel state runs two Glue jobs with the .sync integration so each is awaited, then the Redshift load runs. Tasks retry transient errors with backoff, and a Catch routes any failure to an SNS publish task that alerts the team.
Retry is set on each task; the two pills mark examples.
Sort into groups

Standard or Express?

Exam skills 1.3.3

Choose the Step Functions workflow type for each workload.

Log in to try this activity Interactive activities are free with an account.

Which orchestrator

Several services orchestrate pipelines. The following table indicates when each is the appropriate choice.

ChooseWhen
Step FunctionsThe pipeline spans many services (Lambda, Glue, EMR, Athena, Redshift Data API, SNS) or needs complex branching and error handling
Glue workflowsThe pipeline is only Glue crawlers and jobs
Amazon MWAAThe team already uses Airflow
Worked example

Orchestrating a nightly pipeline

A nightly pipeline must run a crawler, then two Glue jobs in parallel, then a Redshift load, retry transient failures, and alert the team if anything fails. The following table maps each requirement to the Step Functions feature that meets it.

RequirementStep Functions feature
Wait for each Glue job to finishglue:startJobRun.sync integration
Two jobs at onceParallel state
Retry throttling or transient errorsRetry with backoff on the task
Alert on failureCatch routing to an SNS publish task
Run every night at 02:00EventBridge Scheduler starting the state machine

A Glue workflow could orchestrate the Glue parts alone, but the Redshift load and SNS alerts are outside Glue, so Step Functions, which integrates with all of them, is the better orchestrator here.

Check yourself

Which Step Functions feature processes millions of S3 objects in parallel?

Show answer

Distributed Map.

Exam Tips

Remember for the exam

  • To run a Glue job and wait for it to complete, use Step Functions with glue:startJobRun.sync.
  • To process millions of S3 objects in parallel, use Distributed Map.
  • To retry with backoff and route failures, use Retry and Catch.
  • A human approval step uses wait for callback with a task token.
  • High-volume, short-lived event processing suits Express workflows.