1

I am sure I am missing some basic info but my setup is as follows:

I have 1 lambda function and I have 2 State Machines. Each state machine is calling the same lambda function twice in sequence (30 sec pause between calls) Then I have rules setup to trigger the state machines every minute. Below is what each of my state machines look like, each lambda invoke is for the same function.

enter image description here

Each state machine is passing different params to the lambda function so I am trying to get to a situation where my Lambda function is called every 30 seconds with 1 set of params (from statemachine 1), and the same lambda function is called with a different set of params (via statemachine 2) every 30 seconds.

Looking at the lambda function logs it looks like the state machines will not run the lambda function until the other state machine has completed its entire execution (ie calling the lambda function twice). I would expect that the two state machines would run independently of each other and there would be no timing dependency between them?

Is there some limitation because they are all calling the same lambda function? Or is there some setup issue or is this just how it works?

Thanks!

1 Answer 1

1

From the documetation:

When you invoke a Lambda function, the execution will wait for the function to complete. However, it is possible to call Lambda asynchronously using the InvocationType parameter, as seen in the following example

To avoid waiting for oneLambda function to end and continue your step function you have to set the InvocationType to Event in the parameters. However, if your Lambda functions are completely independent from one another using the Parallel execution type may be a better option for you.

step function with parallel execution

{
  "Comment": "Parallel Example.",
  "StartAt": "LookupCustomerInfo",
  "States": {
    "LookupCustomerInfo": {
      "Type": "Parallel",
      "End": true,
      "Branches": [
        {
         "StartAt": "LookupAddress",
         "States": {
           "LookupAddress": {
             "Type": "Task",
             "Resource":
               "arn:aws:lambda:us-east-1:123456789012:function:AddressFinder",
             "End": true
           }
         }
       },
       {
         "StartAt": "LookupPhone",
         "States": {
           "LookupPhone": {
             "Type": "Task",
             "Resource":
               "arn:aws:lambda:us-east-1:123456789012:function:PhoneFinder",
             "End": true
           }
         }
       }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

I thought this kind of setup was needed when you wanted lambda functions to run in parallel within the same step function. I am referring to two state machines running in parallel - would that still need a different Invocationtype?
If I change the invocationtype to event then my step function will not wait for lambda to complete. I dont want that. I want it to wait and only then execute the second function. But I dont want a DIFFERENT state machine waiting for this one to complete
Ok looks like you were right. Even though I would expect the invocationtype to only be relevant WITHIN the state machine. It looks like it becomes a blocker for other state machines too?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.