1

我想按第一个调用的顺序调用函数,然后是第二个,第三个,第四个,然后结束。

我在 AWS 管理控制台中使用选择示例。

为什么第三个和第四个呼叫没有被击中?

AWS Step 函数代码 (JSON)

{
  "Comment": "state functionality",
  "StartAt": "FirstCall",
  "States": {
    "FirstCall": {
      "Type": "Choice",
      "Choices": [
        {
          "Not": {
            "Resource": "rnName",
            "Variable": "$.response",
            "InputPath": "$",
            "ResultPath": "$",
            "OutputPath": "$",
            "StringEquals": "Success Import"
          },
          "Next": "SecondCall"
        },
        {
          "Variable": "$.response",
          "StringEquals": "Success Import ",
          "Next": "ThirdCall"
        },
        {
          "And": [
            {
              "Variable": "$.response",
              "StringEquals": "Success Import"
            },
            {
              "Variable": "$.response",
              "StringEquals": "Success Import"
            }
          ],
          "Next": "FourthCall"
        }
      ]
    },
    "SecondCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "BeforeEnd"
    },
    "ThirdCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "BeforeEnd"
    },
    "FourthCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "BeforeEnd"
    },
    "BeforeEnd": {
      "Type": "Task",
      "Resource": "rnName",
      "End": true
    }
  }
}

在此处输入图像描述

4

1 回答 1

5

如果您尝试按此顺序调用事物:

  1. 第一的
  2. 第二
  3. 第三
  4. 第四

...那么我认为您不想使用Choice状态。该Choice状态专门用于允许您根据当前状态对象的属性值做出分支决策。这将导致一些分支被执行,而另一些被跳过。

顺便说一句,由于Choice状态实际上并没有“调用”任何东西,我建议避免将其命名为“调用某物”,因为这可能会让你失望。Task状态是唯一实际调用任何代码的状态,无论是通过 AWS Lambda 函数,还是通过 Step Functions“活动任务”的概念。

如果您想澄清您要完成的工作,您可以编辑您的问题。

这是你想要做的吗?

AWS 步骤函数

{
  "Comment": "state functionality",
  "StartAt": "FirstCall",
  "States": {
    "FirstCall": {
      "Type": "Choice",
      "Choices": [
        {
          "Not": {
            "Resource": "rnName",
            "Variable": "$.response",
            "InputPath": "$",
            "ResultPath": "$",
            "OutputPath": "$",
            "StringEquals": "Success Import"
          },
          "Next": "SecondCall"
        },
        {
          "Variable": "$.response",
          "StringEquals": "Success Import ",
          "Next": "ThirdCall"
        },
        {
          "And": [
            {
              "Variable": "$.response",
              "StringEquals": "Success Import"
            },
            {
              "Variable": "$.response",
              "StringEquals": "Success Import"
            }
          ],
          "Next": "FourthCall"
        }
      ]
    },
    "SecondCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "FirstCall"
    },
    "ThirdCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "FirstCall"
    },
    "FourthCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "BeforeEnd"
    },
    "BeforeEnd": {
      "Type": "Task",
      "Resource": "rnName",
      "End": true
    }
  }
}

如果您只想按顺序调用四个函数,那么您将使用:

AWS 步骤函数

{
  "Comment": "state functionality",
  "StartAt": "FirstCall",
  "States": {
    "FirstCall": {
      "Type": "Task",
      "Next": "SecondCall"
    },
    "SecondCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "ThirdCall"
    },
    "ThirdCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "FourthCall"
    },
    "FourthCall": {
      "Type": "Task",
      "Resource": "rnName",
      "Next": "BeforeEnd"
    },
    "BeforeEnd": {
      "Type": "Task",
      "Resource": "rnName",
      "End": true
    }
  }
}
于 2018-01-08T04:16:33.073 回答