Reputation: 133
I have a lambda function which is triggered by a FIFO SQS. I only want one instance of the function running. The function invokes a state machine and the state machine takes longer to finish than the lambda function. I want the lambda function to finish only after the step function has completed it's execution.
Upvotes: 2
Views: 7579
Reputation: 41203
Edit - note that the solution below is usually unnecessary now, since AWS has introduced ways to invoke express step functions in a synchronous manner
If you expect your state machine to complete in a reasonable time, then you can get your Lambda (or anything else that starts a state machine execution) to await a response.
This is an accepted pattern, but has quite a few moving parts:
Upvotes: 2
Reputation: 777
AWS Express Step Functions now supports synchronous invocations.
Keep in mind that Express Step Functions are meant for workloads that require higher event rates and have shorter durations. Also, keep in mind that you will be billed based on the number of requests and the duration of the workflow just like lambda.
Upvotes: 5
Reputation: 3992
AWS Step Functions are only invoked asynchronously. A state machine can run for up to 1 year so synchronous invocation is not possible. Depending on your workflow you might find Activities useful.
Activities are an AWS Step Functions feature that enables you to have a task in your state machine where the work is performed by a worker that can be hosted on Amazon Elastic Compute Cloud (Amazon EC2), Amazon Elastic Container Service (Amazon ECS), mobile devices—basically anywhere.
Upvotes: 3