【问题标题】:Invoke step function from particular step through Lambda Function通过 Lambda 函数从特定步骤调用步骤函数
【发布时间】:2020-04-04 17:23:39
【问题描述】:

以下是 step 函数,它在每一步中触发不同的 lambda 函数。 step 函数从 'first_step' 开始。

{
"Comment": "Step function",
"StartAt": "first_step",
"States": {
"first_step": {
   "Type": "Task",
   "Resource": "lambda_function1",
   "Next": "second_step"
 },
"second_step": {
    "Type": "Task",
   "Resource": "lambda_function2",
   "Next": "third_step"
 },
 "third_step": {
   "Type": "Task",
   "Resource": "lambda_function3",
  "End" : true
 }
}
}

现在,我想通过 Lambda 函数从特定步骤 (second_step) 调用步骤函数。 也就是说,一旦我触发另一个 Lambda 函数 (lambda_function4) ,step 函数应该从 second_step 开始执行(跳过 first_step)并一直持续到结束。

另外,我正在使用 Python 创建 Lambda 函数。

【问题讨论】:

    标签: python-3.x amazon-web-services aws-lambda aws-step-functions


    【解决方案1】:

    您需要在函数的开头添加一个选择步骤,以确定接下来要转到哪个 lambda 并传入一个参数来区分。因为您不能使用具体从哪个步骤开始的选项来调用步骤函数

    所以它看起来像:

    {
    "Comment": "Step function",
    "StartAt": "flowDirector",
    "States": {
        "flowDirector": {
        "Type" : "Choice",
        "Choices": [
          {
            "Variable": "$.customVarName",
            "StringEquals": "Cancel",
            "Next": "first_step"
          },
          {
            "Variable": "$.customVarName",
            "StringEquals": "CameFromFunction4",
            "Next": "second_step"
          }
        ],
        "Default": "first_step"
        },
    "first_step": {
       "Type": "Task",
       "Resource": "lambda_function1",
       "Next": "second_step"
     },
    "second_step": {
        "Type": "Task",
       "Resource": "lambda_function2",
       "Next": "third_step"
     },
     "third_step": {
       "Type": "Task",
       "Resource": "lambda_function3",
      "End" : true
     }
    }
    }
    

    然后更新您的 python 代码,将一个额外的参数发送到 step 函数中,以便它可以计算从哪里开始。

    response = client.start_execution(
        stateMachineArn='string',
        name='string',
        input='"{\"customVarName\" : \"CameFromFunction4\"}"'
    )
    

    发件人:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html#SFN.Client.start_execution

    【讨论】:

    猜你喜欢
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 2023-01-19
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多