I start state machine execution by calling API Gateway endpoint. How can I receive execution id in the lambda or how to stop state machine execution in lambda if I don't have execution id?
*this lambda is state machine state.
To stop state machine execution in lambda:
1) Add "name" parameter to your mapping template and pass this parameter to your lambda(you can pass name in the request body if you don't use API Gateway mapping template). It should be unique.
#set($allParams = $input.path('$'))
#set($discard=$allParams.put('executionName', $context.requestId))
{
"input": "$util.escapeJavaScript($input.json('$'))",
"name": "$context.requestId",
"stateMachineArn": "arn here"
}
2) Concatenate execution id:
arn:aws:states:yourRegion:yourAccountId:execution:yourStateMachineName:executionName(which you have specified above)
3) Stop execution with AWS JS SDK method stepfunctions.stopExecution(), using execution id from step 2.