AWS StepFunctions - SageMaker's InvokeEndpoint block throws "validation error" when fetching parameters for itself inside iterator of Map block
I have a state-machine workflow with 3 following states:
- A 'Pass' block that adds a list of strings(SageMaker endpoint names) to the original input. (this 'Pass' will be replaced by a call to DynamoDB to fetch list in future.)
- Use map to call SageMaker endpoints dictated by the array(or list) from above result.
- Send the result of above 'Map' to a Lambda function and exit the workflow.
Here's the entire workflow in .asl.json, inspired from this aws blog.
{
"Comment": "A description of my state machine",
"StartAt": "Pass",
"States": {
"Pass": {
"Type": "Pass",
"Next": "InvokeEndpoints",
"Result": {
"Endpoints": [
"sagemaker-endpoint-1",
"sagemaker-endpoint-2",
"sagemaker-endpoint-3"
]
},
"ResultPath": "$.EndpointList"
},
"InvokeEndpoints": {
"Type": "Map",
"Next": "Post-Processor Lambda",
"Iterator": {
"StartAt": "InvokeEndpoint",
"States": {
"InvokeEndpoint": {
"Type": "Task",
"End": true,
"Parameters": {
"Body": "$.InvocationBody",
"EndpointName": "$.EndpointName"
},
"Resource": "arn:aws:states:::aws-sdk:sagemakerruntime:invokeEndpoint",
"ResultPath": "$.InvocationResult"
}
}
},
"ItemsPath": "$.EndpointList.Endpoints",
"MaxConcurrency": 300,
"Parameters": {
"InvocationBody.$": "$.body.InputData",
"EndpointName.$": "$$.Map.Item.Value"
},
"ResultPath": "$.InvocationResults"
},
"Post-Processor Lambda": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"Payload.$": "$",
"FunctionName": "arn:aws:lambda:<my-region>:<my-account-id>:function:<my-lambda-function-name>:$LATEST"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"End": true
}
}
}
As can be seen in the workflow, I am iterating over the list from the previous 'Pass' block and mapping those to iterate inside 'Map' block and trying to access the Parameters of 'Map' block inside each iteration. Iteration works fine with number of iterators, but I can't access the Parameters inside the iteration. I get this error:
{
"resourceType": "aws-sdk:sagemakerruntime",
"resource": "invokeEndpoint",
"error": "SageMakerRuntime.ValidationErrorException",
"cause": "1 validation error detected: Value '$.EndpointName' at 'endpointName' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-zA-Z0-9](-*[a-zA-Z0-9])* (Service: SageMakerRuntime, Status Code: 400, Request ID: ed5cad0c-28d9-4913-853b-e5f9ac924444)"
}
So, I presume the error is because "$.EndpointName" is not being filled with the relevant value. How do I avoid this.
But, when I open the failed execution and check the InvokeEndpoint block from graph-inspector, input to that is what I expected and above JSON-Paths to fetch the parameters should work, but they don't.
screenshot-of-graph-inspector
What's causing the error and How do I fix this?
In general (as mentioned here in the parameters doc), you also need to end the parameter name with .$
when using a JSON Path.
It looks like you're doing that some places in your sample JSON (e.g. "InvocationBody.$": "$.body.InputData"
), but not in others ("EndpointName": "$.EndpointName"
), so I think the reason you're seeing the validation error here is that Step Functions is trying to interpret $.EndpointName
as literally the name of the endpoint (which doesn't satisfy ^[a-zA-Z0-9](-*[a-zA-Z0-9])*
!)
So suggest you change to EndpointName.$
and Body.$
in your InvokeEndpoint parameters
Relevant questions
Error When I create a Bucket Policy Why?
asked a year agoInvalid security token error when executing nested step function on Step Functions Local
asked 7 days agoOld buckets reappear
asked 3 years agoInternalError creating EBS snapshot
asked 20 days agoStep Functions MAP state billing question
Accepted Answerasked 6 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 agoRoot user cannot change S3 bucket policy
asked a year agoStep Function error handling
asked 2 months agoGet Customer Input block throws error when using Lex as customer input
asked 2 months ago