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

For a lambda executed in a step function, I 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 a way to get the name of the current step in lambda, which is executed in the step function?

+10
source share
3 answers

AWS step functions have released a context object where you can access information about your performance.

You can use it to send executable arn to your lambda.

https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html

+2
source

UPDATE : as of May 23, 2009, this answer is deprecated since AWS introduced a way to access the current step in the step function, see Accepted Answer.


It looks like you're right, the current step is not expanded through the context variable.

Thus, information that allows you to determine at what stage the state machine is located must be transmitted from the previous step (i.e. from the previous lambda). This seems like the most correct option.

Or, as a workaround , you can try inserting pass states before calling lambda functions to pass in an identifier that can help you identify the current stage.

Suppose you have two steps in your destination computer:

 "Step1Test": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:step1test", "Next": "Step2Test" }, "Step2Test": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:step2test", "End": true } 

Here's how you can provide your lambda functions with the current step identifier passed through event.stepId

 "Step1TestEnter": { "Type": "Pass", "Next": "Step1Test", "Result": "Step1Test", "ResultPath": "$.stepId" }, "Step1Test": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:step1test", "Next": "Step2TestEnter" }, "Step2TestEnter": { "Type": "Pass", "Next": "Step2Test", "Result": "Step2Test", "ResultPath": "$.stepId" }, "Step2Test": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:step2test", "End": true } 
+15
source

When using step-by-step functions, I highly recommend specifying a key in the step-by-step function configuration. For my step-by-step functions, I always provide:

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

And so that every lambda call uses the type field to determine which code to call. I found that it is much easier to implement.

+1
source

All Articles