The previous post about integrating SWF in a Spring Boot application received a lot of feedback that convinced us this topic is interesting for our readers.
But from all the replies, there was one that anticipated the subject of a future post we are going to debate today: why not using AWS Step Functions to orchestrate workflows instead of AWS SWF?
AWS Step Functions was announced during re:Invent 2016 and, comparing to SWF, it brings a way simpler method to run workflows, a better integration with other AWS services (especially Lambda, CloudWatch, CloudTrail and CloudFormation) and also a nicer console, but more important, it eliminates all headaches caused by using low level details like aspect oriented programming, tons of dependencies and difficulties in testing.
In this post we’ll show you how to integrate Step Functions into your applications and, to illustrate that, we converted the workflow based on SWF into a state machine run with Step Function. Again, we invite you to spend enough time to understand all concepts and specific terms for AWS Step Function, this post being only an example how to integrate it in your application.
So, let’s see what we have to do run a state machine from our service:
- The equivalent state machine for the demo workflow looks like in the below picture and the JSON to create it could be found here. It’s quite intuitive, we are not going to spend too much time explaining it, for sure if you have basic Step Functions knowledge you could understand each state type. One important aspect is that we chose to run it using activities and not Lambda functions, so our code is going to pull activities and send results back, using JSONs.
- We created 4 activities to run each step of the workflow using the AWS Step Functions console. After you complete step, add the ARNs in the config file and fill the workflow JSON with these values.
- Create the state machine using the JSON and any method is the most convenient for you (Console, API, Command Line).
- Start the service using the instructions described in readme file.
Again, this post only shows how to use AWS State Machine in your applications, but we encourage you do not rush to do that before having at least a basic grasp about this service. We are here to help you with any question you might have and any feedback you might have is kindly received.