Can a lambda in an AWS Step Function know the name of the step it is in?

Viewed 8595

For a lambda executed within a step function, I kind of expected that I could get the name of the current step from the lambda context, but it doesn't seem to be that simple.

Is there any way to get the name of the current step in a lambda that is executed within a Step Function?

4 Answers

Based on the documentation, I was using Parameters and $$ to pass the step function context object into my lambda function. To test and see if it was working, I thought I could go to the step function console, start a new execution and see the context object being passed into the step function on the "Step Input" tab. To my dismay, it wasn't displayed there. I added some diagnostic logging to the lambda function serializing the input to JSON and logging out to CloudWatch. Cloudwatch logs showed that the context object was being passed in.

Anyway, thought I would post this here to maybe help someone avoid the time I spent trying to figure this one out. It gets passed in, just doesn't show up in the step function console.

I highly recommend when using step functions to specify some sort of key in the step function configuration. For my step functions I always provide:

"ResultPath": "$",
"Parameters": {
  "source": "StepFunction",
  "type": "LAMBDA_METHOD_SWITCH_VALUE",
  "payload.$": "$"
},

And have each call to lambda use the type field to determine what code to call. I have found this to be much easier to implement.

Related