Home > Blockchain >  Get execution arn of Step function inside one of its lambdas (Serverless Framework)
Get execution arn of Step function inside one of its lambdas (Serverless Framework)

Time:09-23

Using the Serverless framework and step function framework, can I get execution ARN from inside lambda function?

CodePudding user response:

You can output execution ARN like "Execution.$": "$$.Execution.Id". (doc)

Below is a simple demo with a Lambda function.


Nodejs Lambda function with name HelloFunction (only for outputting to CloudWatch log):

exports.handler = (event, context, callback) => {
    console.log(event);
};

Step function (just put "$$.Execution.Id" to HelloFunction lambda):

{
  "Comment": "put execution ARN to Lambda",
  "StartAt": "HelloWorld",
  "States": {
    "HelloWorld": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "HelloFunction",
        "Payload": {
          "Execution.$": "$$.Execution.Id"
        }
      },
      "End": true
    }
  }
}

Output will be like:

2021-09-23T00:05:07.197Z    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  INFO    {
  Execution: 'arn:aws:states:<region>-1:111122223333:execution:MyStateMachine_lambda_callback_service_integration_pattern:xxxxxxxxx-xxxx-xxxxxxxxxxxxx'
}
  • Related