Remove unused states from an AWS State Machine definition with minimal effort
npm i @enfo/shake-state-machine -g
Add a state machine definition to your clipboard with your desired start state as StartAt. Invoke the package and if all went well your clipboard will now contain a state machine with no unreachable states.
Alternatively the package can be invoked using npx.
Let us have a look at an AWS State Machine definition.
Execution is successful.
Let us try to modify the State Machine so it skips the Hello state and starts at World. Attempting to save will result in an error regarding an unreachable state.
Copy the definition into your clipboard and run the package. Paste to the definition input field afterwards
The new state machine definition is ready to be used. When used in the wild you can have your State Machine fixed in a matter of seconds!
How it works
Under the hood the package runs a Depth-first search starting at StartAt. After completing it builds a new state machine using only the visited states.