What is the AWS Step Functions service?
Will try to keep this part short as there are enough articles and documentations presenting this.
So…
As described, this is a “serverless orchestration service”.
It allows the user to define state machines (workflows) that connects various tasks (states). To make it easy, AWS provides a Workflow Studio which simplifies the definition step of the workflows.
There are two options for workflow types:
- Standard
- Express
Besides all the differences defined in the documentation, an important one for Hybrid architectures is the Activity support:
In the following example we are going to use the Standard workflow, as we also need to run Activities.
Description of the example
We are going to implement a State Machine that combines the AWS Lambda with an on-premises project.
The code for this part of the tutorial can be found here:
- CloudFormation stack
- getServerlessState —in the stack
- getLocalState — Activity pull code (always reads for waiting tasks)
GetActivityTaskResult getActivityTaskResult =
client.getActivityTask(new GetActivityTaskRequest().withActivityArn(ACTIVITY_ARN));
if (getActivityTaskResult.getTaskToken() != null) {
System.out.println("Found result from previous step.");
try {
JsonNode json = Jackson.jsonNodeOf(getActivityTaskResult.getInput());
String result = code.getLocalCode(json.get("value").intValue());
client.sendTaskSuccess(
new SendTaskSuccessRequest().withOutput(
result).withTaskToken(getActivityTaskResult.getTaskToken()));
} catch (Exception e) {
client.sendTaskFailure(new SendTaskFailureRequest().withTaskToken(getActivityTaskResult.getTaskToken()));
}
} else {
Thread.sleep(1000);
}
- DefaultState — in the stack
“DefaultState”: {
“Type”: “Fail”,
“Cause”: “Value provided does not cover our cases (private & 0)!”
}
The results are displayed in a nice manner in the Graph inspector:
Conclusion
It is a great service which has many features and the fact that it allows to be used with local ran code (by using Activities), it makes it even preferable.
No costs were incurred while running this example.
During the test phase there were some issues found, for example if two executions reach the getLocalState and the application pulling is down/disconnected, after the application (which does the pull on the Activity) gets back up one of the executions remains hanging -> times out.
The code used to run this tutorial is located: