Sub topic 1
Why Orchestrate Workflows with AWS Step Functions
Prerequisites
Assume you know basic AWS accounts, IAM roles, JSON, Lambda, and the AWS CLI. You should also understand that network calls can fail and may need retries.
Why use Step Functions?
AWS Step Functions coordinates a workflow across AWS services. A workflow is a sequence of business steps, such as validating an order, charging a payment, and sending a notification.
Without Step Functions, application code often chains these calls directly. That code must track progress, handle retries, record errors, and decide what happens next. Step Functions stores the execution state and gives you a visual execution history.
Use it when a process has multiple steps, conditional paths, parallel work, delays, or long-running operations. It is less suitable for a single short function call.
State machines and Amazon States Language
A state machine is the definition and runtime model of a workflow. You write its states in Amazon States Language (ASL), a JSON-based language. Each state performs work, controls flow, or ends the execution.
A state has a name and a Type. The StartAt field identifies the first state. Next moves to another state, while End finishes successfully.
Doing work with Task states
A Task state performs an operation, such as invoking Lambda. The optimized Lambda integration below passes the entire input as the function payload.
{
"StartAt": "ValidateOrder",
"States": {
"ValidateOrder": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-east-1:123456789012:function:ValidateOrder",
"Payload.$": "$"
},
"Next": "Accepted"
},
"Accepted": {
"Type": "Succeed"
}
}
}The Step Functions execution role needs permission to invoke that Lambda function.
Controlling flow
A Choice state selects a path from input. Wait delays execution. Pass transforms or forwards data without calling a service. Succeed ends successfully, and Fail ends with an error. Combine these states to express business rules instead of hiding them inside one large function.
>``callout note >Keep orchestration decisions in the state machine and business calculations in services such as Lambda. This makes each part easier to test and inspect. >``
Exercise
Which state should route an execution based on whether $.approved is true?
Show answer
Use a Choice state with a BooleanEquals rule.