15

For a lambda executed within a step function, I want to know the current execution id of AWS State Machine within that. Is there a way to know this within the step function?

ajay0221
  • 319
  • 1
  • 4
  • 10
  • Possible duplicate of [Can a lambda in an AWS Step Function know the "execution name" of the step function that launched it?](https://stackoverflow.com/questions/48854398/can-a-lambda-in-an-aws-step-function-know-the-execution-name-of-the-step-funct) – vaquar khan Sep 30 '19 at 13:46

2 Answers2

29

Old question but the answer is outdated - you can now get this inside the step function - with $$.Execution.id. Example I'm using:

"run_task": {
  "Type": "Task",
  "Parameters": {
    "task.$": "$.task",
    "executionId.$": "$$.Execution.Id"
  },
  "Resource": "${runTaskLambdaArn}",
  "End": true
}
Callum M
  • 1,635
  • 19
  • 27
  • What about passing the execution id to SageMaker batch transform job name? I'm stuck here for a whole morning now, I raised a question (https://stackoverflow.com/questions/65609804/how-to-append-stepfunction-execution-id-to-sagemaker-job-names) it would be great if you can take a look, thanks. – wawawa Jan 07 '21 at 10:29
  • 1
    Just a heads up: This returns the ARN of the stepfunction + the execution name. (`arn:name`) which is considered the "id". If only the execution id itself (i.e. the generated id if not manually set) is needed then `$$.Execution.Name` can be used – Maverick283 Aug 28 '23 at 09:07
0

Unfortunately, AWS Step Functions don't have this feature yet. A common pattern is to define the execution ID (instead of using the auto-generation) and adding it to the input of the execution (from there on, you can use it inside your tasks.

Reference: https://forums.aws.amazon.com/thread.jspa?messageID=754179

Lucas Saldanha
  • 891
  • 7
  • 13