It allows the user to define state machines (workflows) that connect various tasks (states). To make it easy, AWS provides a Workflow Studio that 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: