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

AWS Step Functions released Context Object where you can access information about your execution.

You can use it to send the execution arn to your lambda.

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


UPDATE: as of 05/23/2019 this answer is outdated, since AWS introduced a way to access current step within a step function, see the accepted answer.


Looks like you are right, the current step doesn't get exposed through the context variable.

So, the information that would allow you to identify what stage is the state machine currently in, should be passed from the previous step (i.e. from the previous lambda). This seems to be the most correct option.

Or, as a workaround, you could try inserting pass states before calling your lambda functions to pass an id that could help you to identify the current stage.

Suppose you have two steps in your state machine:

"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 is how you can provide your lambda functions with current step id passed via 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
}