AWS StepFunctions support a callback model. The documentation reads:
Callback tasks provide a way to pause a workflow until a task token is returned. A task might need to wait for a human approval, integrate with a third party, or call legacy systems. For tasks like these, you can pause Step Functions indefinitely, and wait for an external process or workflow to complete. For these situations Step Functions allows you to pass a task token to some integrated services. The task will pause until it receives that task token back with a SendTaskSuccess or SendTaskFailure call.
If a state machine is defined using CDK to call a lambda as part of a Step Function map (i.e. it's in a loop):
LambdaInvoke myLambdaStepFunction = LambdaInvoke.Builder.create(this, "MyLambdaStepFunction ")
.lambdaFunction(myLambdaFunction)
.integrationPattern(IntegrationPattern.WAIT_FOR_TASK_TOKEN)
.build();
stepfunctions.Map loopSteps = stepfunctions.Map.Builder.create(this, "LambdaLoop")
.maxConcurrency(1)
.build();
loopSteps.iterator(myLambdaStepFunction);
StateMachine stateMachine = StateMachine.Builder.create(this, "StateMachine")
.stateMachineType(StateMachineType.STANDARD)
.timeout(Duration.minutes(5))
.definition(deployAllIncrementallySteps)
.build();
when does the wait for token occur?
- Is it after the lambda is invoked for the first time?
- Is it before the lambda is invoked for the first time?