States & the Amazon States Language

The handful of state types you'll use, and what a definition looks like.

2 min read

Workflows are written in JSON called the Amazon States Language (ASL), or drawn in the visual Workflow Studio, which generates the JSON for you.

StateDoes
TaskDoes work: invokes Lambda, or calls one of 200+ AWS services directly
ChoiceBranches based on data ("if wordCount > 500…")
ParallelRuns several branches at the same time
MapRuns the same steps for each item in a list
WaitPauses for a duration or until a timestamp
PassPasses or reshapes data, useful for testing
Succeed / FailEnds the execution

Direct service integrations: no glue code

A Task can call AWS services directly, such as DynamoDB PutItem, SNS Publish, or Bedrock InvokeModel, so you don't need a Lambda function whose only job is to call another API.

Try it

notesnap.asl.json
{
  "Comment": "Summarize a note, save it, notify the user",
  "StartAt": "Summarize",
  "States": {
    "Summarize": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": { "FunctionName": "notesnap-summarize", "Payload.quot;: "quot; },
      "ResultSelector": { "summary.quot;: "$.Payload.summary" },
      "ResultPath": "$.result",
      "Next": "SaveSummary"
    },
    "SaveSummary": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName": "notesnap-summaries",
        "Item": {
          "noteId": { "S.quot;: "$.noteKey" },
          "summary": { "S.quot;: "$.result.summary" }
        }
      },
      "ResultPath": null,
      "Next": "Notify"
    },
    "Notify": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sns:publish",
      "Parameters": {
        "TopicArn": "arn:aws:sns:us-east-1:123456789012:notesnap-summary-ready",
        "Message.quot;: "$.result.summary"
      },
      "End": true
    }
  }
}

Reading the data flow

  • $ is the current state's input. Payload.$: "quot; passes it all to Lambda.
  • ResultSelector picks just the fields you need from the result.
  • ResultPath: "$.result" adds the result to the input instead of replacing it, so later steps still see noteKey.
  • ResultPath: null throws the result away and keeps the input unchanged.
Note

Fields ending in .$ take their value from the data (a JSONPath). Without .$, the value is a literal. Newer workflows can also use JSONata expressions instead of JSONPath.

Key takeaways

  • Task, Choice, Parallel, Map, and Wait cover most workflows.
  • Direct integrations call AWS services without glue Lambdas.
  • ResultPath controls how each step's output merges into the data.

Check your understanding

Pick an answer to see the explanation.

  1. 1. You want to process each of 500 files with the same steps in parallel. Which state?

  2. 2. What does "ResultPath": null do?