AWS StepFunctions - SageMaker 的 InvokeEndpoint 在 Map 块的迭代器内获取自身参数时抛出“validation error”

0

【以下的问题经过翻译处理】 我有一个具有以下 3 个状态的状态机工作流:

我的工作流程截图

  1. 将字符串列表(SageMaker 端点名称)添加到原始输入的“Pass”块。 (这个“Pass”将被替换为调用 DynamoDB 以在未来获取列表。
  2. 使用 map 从上述结果中调用由数组(或列表)指定的 SageMaker 端点。
  3. 将上述“Map”的结果发送到 Lambda 函数并退出工作流程。

这是 .asl.json 中的整个工作流程,灵感来自 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
    }
  }
}

从工作流程中可以看出,我正在遍历前一个“Pass”块中的列表,并将它们映射到“Map”块内进行迭代,并尝试在每次迭代中访问“Map”块的参数。迭代适用于迭代器的数量,但我无法访问迭代内的参数。我收到此错误:

{
  "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)"
}

因此,我认为该错误是因为“$.EndpointName”未填充相关值。我该如何避免这种情况?

但是,当我打开失败的执行并从 graph-inspector 检查 InvokeEndpoint 块时,输入的是我所期望的,并且在 JSON-Paths 之上获取参数应该有效,但它们不起作用。

图形检查器的屏幕截图

是什么导致了错误,我该如何解决?

profile picture
专家
已提问 8 个月前51 查看次数
1 回答
0

【以下的回答经过翻译处理】 通常情况下(如参数文档中所述),当使用JSON Path时,您还需要使用“.$. ”结束参数名称。

看起来您在样例JSON中的某些地方已经这样做(例如,“InvocationBody.$”:“$ .body.InputData”),但在其他地方没有(“EndpointName”:“$ .EndpointName”),因此我认为您在这里看到验证错误的原因是步骤功能试图将“$ .EndpointName”解释为字面上的端点名称(它不能满足“ ^ [a-zA-Z0-9]( - * [a-zA-Z0-9]) * ”!)。

因此,建议您在InvokeEndpoint参数中更改为EndpointName.$和Body.$.

profile picture
专家
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则