How to access API Parameters of a node and add them as part of it's own output json in AWS Step Functions?
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?
Hi,
Two possible solution that I can see are:
- Define
ResultSelector
in each state to insert the staticEndpointName
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"
}
}
- Pass the
EndpointName
into Amazon SageMaker'sCustomAttributes
Request/Response elements, SageMaker InvokeEndpoint Response Elements. AddingEndpointName
to the model's response in theCustomAttributes
element will result in the desired state result.
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-1
th position) send the Parameters current node(at i
th position) need as Parameters and fill them dynamically and then access them from it's output.
Relevant questions
AWS Step Function Retires | Retry With Jitter
asked 5 months agoHow to access API Parameters of a node and add them as part of it's own output json in AWS Step Functions?
asked 2 months agoAWS StepFunctions - SageMaker's InvokeEndpoint block throws "validation error" when fetching parameters for itself inside iterator of Map block
Accepted Answerasked 2 months agoBatch ArrayProperties configured from input in Step Functions
Accepted Answerasked 4 months agoCan I specify GET URL path parameter in step function?
asked 3 months agoAWS StepFunctions: sum() function returns error about not finding path
asked 2 months agoEasy Interactive Python - Is there something akin to VS Code's Shift+Enter for sending code to ipython terminal in Cloud9?
asked 12 days agoWhen to invoke a lambda directly or via API Gateway
asked 5 months agoImplementing message node in lex
asked 3 months agoServices vanished after enabling all features in Organization
asked 3 months ago