user1187968
user1187968

Reputation: 7986

AWS Step Function: state A pass lambda output to state B

My AWS lambda function check-version-lambda returns {"latest": "yes"} or {"latest": "no"}.

I have the AWS step function below, to pass above result to next state.

The next state process_version is a choice state, how do I retrieve the input inside Choices? What to fill in for <???>?

  {
      "StartAt": "check_version",
      "States": {
        "check_version": {
          "Type": "Task",
          "Resource": "arn:aws:lambda:us-east-1:000:function:check-version-lambda",
          "OutputPath": "$.latest",
          "Next": "process_version"
        },
        "process_version": {
          "Type": "Choice",
          "Choices": [
            {
              "Variable": "<???>",
              "StringEquals": "yes",
              "Next": "next_state"
            },
            {
              "Variable": "<???>",
              "StringEquals": "no",
              "Next": "next_state"
            }
          ],
          "Default": "next_state"
        }
      }
    }

Upvotes: 3

Views: 7229

Answers (1)

Simon
Simon

Reputation: 223

In your "check_version" state, you can use

"ResultPath": "$.result",
"OutputPath": "$.result",

to explicitly configure the step function to put the result of the lambda (e.g. {"latest": "yes"}) into the result property of the input object. OutputPath tells the step function to only select that result as state output and hand it over to the next state.

In your "process_version" state, you should then be able to use:

"Variable": "$.result.latest",
"StringEquals": "yes",
"Next": ...

Source: https://docs.aws.amazon.com/step-functions/latest/dg/input-output-example.html

Upvotes: 3

Related Questions