Step functions are very useful, if you are planning to build a workflow across multiple AWS services. It connects different AWS resources and gives us control over the execution path based on predefined conditions and feedback.
If you have been using ECS to run a task as a job or on schedule,there is a better way to run and handle the execution using the Step functions.
In this post we will create simple Step function
- Which triggers an ECS task.
- Check the result of the execution.
- Retry the task on failure.
The execution workflow is as below.
ECS task details
Assuming you already have an ECS cluster and corresponding Task definition to run the task,get the necessary details to use inside step functions like
- ECS Cluster ARN
- ECS task ARN
They are required to call the ECS activities from the Step Function.
Prepare Step Function
Once you have the details use the sample JSON definition for the function.
The definition Runs the ECS task and check the error type TaskFailed , retires after 10 seconds and tries 3 more times until success.
Trigger Step function
Once the definition and function are ready, you see a flow graph of the execution and ready to be run.
Finally
In this example we took an ECS task and added an simple feedback loop to handle the task failure with logging.
This can be further extended to run between different services especially connection Lambda, creating a continuous execution flow.