Search code examples
pythonamazon-web-serviceslambdaaws-lambdaaws-step-functions

Is there any way to know if a Lambda was invoked by a step function?


Is there any way for a lambda function to know if it was invoked inside a step function? Without requiring the developer to pass arguments inside the step function from step to step. I checked the context and it does not provide such information.

I would imagine that aws would provide some kind of unique identifier for step functions which would be passed to lambda functions.


Solution

  • There is no default way to do so. Step Functions by itself does not pass any event details when invoking a Lambda function.

    As you mentioned, you can pass input via the InputPath, ResultPath and OutputPath from step to step. Alternatively, you can declare Parameters in your state machine:

    {
         "StartAt": "HelloWorld",
         "States": {
             "Echo": {
                 "Type": "Task",
                 "Resource": "arn:aws:lambda:us-east-1:1234567890:function:echo",
                 "Parameters": {"invocation_type": "StepFunction"},
                 "End": true
              }
         }
    }
    

    The above function will be invoked with {"invocation_type": "StepFunction"} event.