How to access API Parameters of a node and add them as part of it's own output json in AWS Step Functions?

1

Here's some part of my StepFunction: https://i.stack.imgur.com/4Jxd9.png

Here's the workflow for the "Parallel" node:

    {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "InvokeEndpoint01",
          "States": {
            "InvokeEndpoint01": {
              "Type": "Task",
              "End": true,
              "Parameters": {
                "Body": "$.Input",
                "EndpointName": "dummy-endpoint-name1"
              },
              "Resource": "arn:aws:states:::aws-sdk:sagemakerruntime:invokeEndpoint"
            }
          }
        },
        {
          "StartAt": "InvokeEndpoint02",
          "States": {
            "InvokeEndpoint02": {
              "Type": "Task",
              "End": true,
              "Parameters": {
                "Body": "$.Input",
                "EndpointName": "dummy-endpoint-name2"
              },
              "Resource": "arn:aws:states:::aws-sdk:sagemakerruntime:invokeEndpoint"
            }
          }
        }
      ],
      "Next": "Lambda Invoke"
    },

I would like to access the EndpointName of each node inside this Parallel block and add it as one of the keys of that particular node's output, without modifying the existing output's body and other headers.(in the above json, EndpointName can be found for first node inside the Parallel at $.Branches[0].States.InvokeEndpoint01.Parameters.EndpointName)

Here's output of one of the node inside the Parallel block:

{
  "Body": "{xxxx}",
  "ContentType": "application/json",
  "InvokedProductionVariant": "xxxx"
}

and I would like to access the API Parameter and make it something like below:

{
  "Body": "{xxxx}",
  "ContentType": "application/json",
  "InvokedProductionVariant": "xxxx",
  "EndpointName": "dummy-endpoint-name1"
}

How do I do this?

2 Answers
1

Hi,

Two possible solution that I can see are:

  1. Define ResultSelector in each state to insert the static EndpointName value into the state's result. Adding a value "Output.$": "$" will copy the full, un-manipulated, state result into that key.

Example Definition

{
    "StartAt": "InvokeEndpoint02",
    "States":
    {
        "InvokeEndpoint02":
        {
            "Type": "Task",
            "End": true,
            "Parameters":
            {
                "Body": "$.Input",
                "EndpointName": "dummy-endpoint-name2"
            },
            "Resource": "arn:aws:states:::aws-sdk:sagemakerruntime:invokeEndpoint",
            "ResultSelector":
            {
                "Output.$": "$",
                "EndpointName": "dummy-endpoint-name2"
            }
        }
    }
}

Example Output

{
  "EndpointName": "dummy-endpoint-name2",
  "Output": {
    "Body": "{xxxx}",
    "ContentType": "application/json",
    "InvokedProductionVariant": "xxxx"
  }
}
  1. Pass the EndpointName into Amazon SageMaker's CustomAttributes Request/Response elements, SageMaker InvokeEndpoint Response Elements. Adding EndpointName to the model's response in the CustomAttributes element will result in the desired state result.
AWS
answered 2 years ago
0

2nd way from @Edward_S's answer does fulfill my needs. but, someone stumbling on this question in the future would want to learn how this can be accomplished.

I learned from AWS Support that it is not possible to access the parameters(or API Parameters) of a node. If you want to access the Parameters, make a node(at i-1th position) send the Parameters current node(at ith position) need as Parameters and fill them dynamically and then access them from it's output.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions