Does anyone else feel like Step Functions have a lot of potential, but the implementation was kind of half arsed? There’s so much basic functionality lacking. There are so few comparison operators for Choice statements, and error handling is ridiculous.
AWS documentation says that States.ALL catches all errors. But if you reference $.myvar and that doesn’t exist, it will cause an error which is not caught by States.ALL. *There is no way to catch all errors. I had to make a second step function which does nothing but invoke the first one, and then handle an error.
You cannot catch errors from a Choice task (e.g. from looking up a path that doesn’t exist), because Catch is not supported for Choice
You cannot compare two variables in a Choice task. You can only compare variable to hard coded constant
You cannot check the length of an array in a Choice task
You cannot check whether a variable is defined in a Choice task. ie. It’s not possible to say if 'x' in d and d['x'] == 1: foo(d['x']) else: bar()
They say you can use JSONPath, but when I try JSONPath errors I get errors. I’ve had different support agents give me confliction advice about whether this is possible.
AWS recommend adding TimeoutSeconds to tasks, and say they can be used on any task. But they’re not allowed in Parallel tasks. The documentation is incorrect.
AWS recommend using Pass tasks as placeholders for Lambdas while you’re constructing your step function. But Pass tasks can’t take Retry or Catch fields. This means it’s not possible to draft a step function with Pass tasks as placeholders if you have tasks that are only used to handle caught errors.
You can’t write step functions in Yaml. That means you can’t have comments, and it’s very easy to write invalid code because of a comma trailing at the end of a list.
If one branch in a Map or Parallel task fails, all other tasks are immediately cancelled. It’s not feasible to configure it to continue executing the other branches. I want to say “for each piece of equipment, send a signal”. If piece 500 fails to be actuated, I don’t want pieces 1 to 499 to be cancelled mid-way through actuation
you can’t do a dictionary lookup
you can’t decrement a variable to do for(a = 10; a > 0; a-- )
re: JSONPath, only a subset of the DSL is available, and it’s not available at all in some places you likely want to use it.
StepFunctions definitely don’t have a complete DSL and you need to add a bunch of Pass tasks to do what would be simple in a programming language. That said I’ve generally found them to be sufficient.
The tooling is definitely weak… e.g. the linter doesn’t work in a definition embedded in CloudFormation. I’ve considered writing a cfn_nag plugin to do this. Having said that CDK has higher level consrtucts in beta now which will definitely be a quality of life improvement.
I hope they will somehow move Step Functions to the CDK (with some cool syntax like Apache Airflow’s DAGs), because maintaining JSON is horrible. A man can dream though.
In case of failure, you also can’t just fix your task and retry where you left off, you have to restart the entire state machine. That sucks if you’re in ETL/ML world.
I haven’t used it , but want to use it since lambda calling another lambda is an anti pattern. I will start exploring it.
But I have similar feedback about SSM Automation. It has great potential, but half baked. The documentation is really of not much use when it’s about creating custom do documents.
I would like to understand why lambda invoking a lambda would be considered an anti pattern (within reason). I look at it like an rpc in an soa/Microservice architecture.
>If one branch in a Map or Parallel task fails, all other tasks are immediately cancelled. It’s not feasible to configure it to continue executing the other branches. I want to say “for each piece of equipment, send a signal”. If piece 500 fails to be actuated, I don’t want pieces 1 to 499 to be cancelled mid-way through actuation
I worked around this by creating a Parallel task inside my Map task, with a single branch, and putting the error handler on the Parallel. So each branch of the Map has its own global error catch. This saved me from having to put the error handler on every single inner task as well as allowing other parts of the Map to continue.
Single-branch Parallel tasks can be considered an error boundary in that way.
I don’t believe any of the conclusions you came to are incorrect, so if those are things you need for some application I would agree that SF is not a good choice.
That being said, we have moved a lot of our media processing to a Step Functions project, and we’ve been happy with the results. I’m the primary maintainer on that and I would say these are my biggest frustrations:
Not being able to use YAML. I could understand SF itself only accepting JSON, but CloudFormation/SAM should support a YAML template and do the conversion. I’ve considered having our build process generate the JSON from YAML, but now that there’s an ASL linter I don’t want to lose that during editing.
There are many times where I wish I could do more with OutputPath, primarily drop specific keys that I don’t want to pass along.
As you said, state machine-level runtime errors, like accessing a nonexistent value in a Choice, are unnecessarily hard to deal with. The first state in this machine basically just makes sure all the values that are needed throughout the execution exist.
Extremely limited Fargate support. There’s no native way to return anything from a Fargate execution, which turns into a ton of extra work to write results somewhere, and have a Lambda that reads them. Or doesn’t read them because they don’t exist and you have to start to make assumptions about why. There are a number of things we do in Rails workers right now that I’d love to move to SF+Fargate, but I probably won’t until you can actually return a value or error to the state machine.
Even with those issues, I’ve been pretty happy with how well this setup has worked for us. I don’t mind when an AWS service provides the most basic building blocks of something, and the expectation is you build a lot of things on top of that. As long as how it’s billed I’m ok. It’s always nice when they do some more of the legwork down the road and I can delete code, but for now it doesn’t bother me too much. I’ve also found the pricing to be pretty good.
I have read it in multiple places including this sub. I’m not a developer, I only write simple scripts for some automation, and for my use cases , I haven’t run into issues because of this.
However, one argument against it is that the parent function will keep running until the child is finished running and returned, which increases the costs. They mostly recommends step functions for this purpose.
Usually this is the case in a Microservice design as you want the request/response life cycle to complete as you are using the response from the remote procedure to continue functioning. This would be the same as if you were calling a restful endpoint, so advantages that need to be considered is in memory local time vs remote execution time. But that’s fighting other patterns.
I have heard a few people call it an anti pattern but not be able to talk on it intellectually, this is how fud starts and spreads. And then someone designing a solution will avoid looking down this pattern because they heard online its an anti pattern. This can lead to a worse design.
Calling this an anti pattern is akin to calling soa and Microservices an anti pattern (and trust me, there are some people excited to do that, however that’s a lot larger conversation than just this). It’s not, however you need to understand the costs you’re incurring and weigh the pros vs cons.
I also have a love/hate relationship with Step Functions. One recent update for those of us using CloudFormation + SAM is that we can define a Step Function in YAML. Used it in a recent personal project and preferred it over JSON.
You can invoke a lambda function synchronously or asynchronously. The parent function will not wait for the child to complete when invoked asynchronously. Using boto3 in python, you set the invocation type as Event(asynchronously) or RequestResponse (synchronously).
I wouldn’t call it an anti-pattern, but I do prefer the workflow mechanism that Step Functions brings to the table. It’s easier to wrap my head around whats going on. Plus I like having the error handling and retry settings at the workflow level.
On a related note, Step Functions are nice for wrapping up a series of lambdas into a transaction of sorts. ie Lambda C failed so we need to do some upstream cleanup with Lamdba A and B.
Sorry, I’m not trying to say Step Functions is bad by any means. I use step functions myself, but I felt that something needed to be said about calling RPC an anti-pattern.
To kinda clear up the messaging, when I have a function that is daisy chaining actions together, step functions all the way. When I have a function that is using an engine or something similar to a level 2 cache, I prefer invoking. And when I can library the functional (because it’s going to be shared across multiple services) and I can create a utility or reusable package I like using layers/package management.
Wait until you find out that sometimes sfn can’t talk to lambda and lambda returns a 500 and you have to tell it to retry as opposed to it doing it on its own so you end up needing a retry for every step
Just have your lambda enqueue sqs and have a lambda trigger for the sqs. That can solve any issues with lambda calling lambda and is cheaper than sfn. Add a dlq to keep track of any errors.
From my view it’s failure prone with no good recovery mechanism. Lambdas arent guaranteed to be executed. You can run into service errors and concurrency limits.