I am new to aws and doing a PoC around aws lambda and step function. So my problem statement is: A http request comes to API gateway which triggers a lambda function and through that lambda I am trigerring a step function something like awsStepFunction.startExecution(executionRequest)
Now, since this is asynchronous in nature it just triggers step function and returns response but I want to return a response from lambda only when the execution of lambda is completed or failed.
I am using getExecutionHistory recursively to get the response of execution but that effects my execution time and also when doing load testing getting Throttling exception saying rate exceeded
ExecutionResult result = awsStepFunction.startExecution(executionRequest);
getHistory(awsStepFunction, result);
private void getHistory(awsStepFunction, result){
List<HistoryEvents> list = GetExecutionHistory(request).getEvents;
while(true) {
If(list.get(0).getId == 71 || list.get(0).getStatus.equals("ExecutionFailed")){
return;
} else {
Thread.sleep(1000);
getHistory(awsStepFuncrion,result);
}
return;
}
}
71 is the final id of the event confirming that execution has succeeded.
But here when multiple requests are triggered getting error 400 Throttling exception rate exceeded in cloudwatch logs and hence getting a http response of 502 bad gateway
You want to get response from Lambda or you want to know the response from Step function ? Lambda will start the step function an return that's it . In that case you will not want to get response from Lambda . Where do you want to get response API gateway ? Amazon API has 29 sec time out .
so it comes down to one option to get the response back from Step function . What you can do is to run step function. Let it take its own time and when finished create a trigger .
You can have a Event bridge Event Bridge on SUCCEEDED,FAILED,TIMED_OUT and on ABORTED. Target of Event bridge will be another lambda function which can indicate you the status of the step function .
If you want to get the history of step function like input and output in every step function step function you can very well call getExecutionHistory in this lambda function .