Add Choice State

Learn to implement the Choice state in a workflow.

We'll cover the following

Before we start testing our Map state, let's add one important thing. As we remember well, in the previous step, we check that we have all the ingredients. It would be useful to handle a case where we don't have enough ingredients, because without this we cannot continue with our confectionery production.

The Choice state in the workflow

In our case, we want to add a Choice state to decide whether to continue with the mixing process or terminate the execution if there are insufficient ingredients. A Choice state allows the execution of a state machine to branch based on the value of a specific field in the JSON input.

We'll add a Choice state after the IngredientPreparation state, before the MixingIngredients state. We'll evaluate the statusCode returned by the IngredientPreparation Lambda function. If the status code is 200, it means we have sufficient ingredients, and we can proceed to the MixingIngredients state. Otherwise, if the status code is 400, we'll move to a Fail state, terminating the execution.

Let's edit the serverless.yml file.

Get hands-on with 1200+ tech skills courses.