python-3.x - 通过 Lambda 函数从特定步骤调用步骤函数
问题描述
以下是在每一步中触发不同 lambda 函数的 step 函数。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) 调用 step 函数。也就是说,一旦我触发另一个 Lambda 函数 (lambda_function4) ,step 函数应该从 second_step 开始执行(跳过 first_step)并一直持续到结束。
另外,我使用 Python 来创建 Lambda 函数。
解决方案
您需要在函数的开头添加一个选择步骤,以确定接下来要转到的 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\"}"'
)
推荐阅读
- node.js - 你能帮我解决这个节点js错误吗?“Module_Not_Found”
- unity3d - gameobject在游戏视图Unity中的错误位置实例化
- angular - Ngx-bootstrap 日期选择器自定义范围
- c - 在C中递归地在排序数组中添加元素
- linux - i915驱动的加载
- python - Python3 - 列表理解:不在嵌套列表中
- python - 在 tkinter 应用程序中调用 Matplotlib 会更改 Windows 10 上的根窗口大小
- fedora - Podman 内存锁限制
- android-studio - 如何播放介绍,仅在安装应用程序时播放,单击按钮时播放?
- python - ValueError:Dimensions must be equal,但在自制层中是64和32