"Athena.InvalidRequestException" 在 Step 函数中

"Athena.InvalidRequestException" in Step function

我正在尝试从输入中读取查询字符串,但步骤函数给出了 - “Athena.InvalidRequestException”

{
  "StartAt": "CallFunction",
  "States": {
    "CallFunction": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-west-2:12345:function:readFile",
      "ResultPath": "$.query",
      "Next": "Start an Athena query"
    },
    "Start an Athena query": {
      "Resource": "arn:aws:states:::athena:startQueryExecution.sync",
      "Parameters": {
        "QueryString": "$.query",
        "WorkGroup": "primary",
        "ResultConfiguration": {
          "OutputLocation": "s3://test_athena/test1"
        }
      }
  }
}

启动 Athena 查询状态的输入:

{
  "Comment": "Insert your JSON here",
  "query": "\"SELECT *   FROM test1   LIMIT 10;  \""
}

在启动 Athena 查询状态时出现以下错误:

{
  "resourceType": "athena",
  "resource": "startQueryExecution.sync",
  "error": "Athena.InvalidRequestException",
  "cause": "line 1:1: mismatched input '$'. Expecting: 'ALTER', 'ANALYZE', 'CALL', 'COMMIT', 'CREATE', 'DEALLOCATE', 'DELETE', 'DESC', 'DESCRIBE', 'DROP', 'EXECUTE', 'EXPLAIN', 'GRANT', 'INSERT', 'PREPARE', 'RESET', 'REVOKE', 'ROLLBACK', 'SET', 'SHOW', 'START', 'UNLOAD', 'UPDATE', 'USE', <query> (Service: AmazonAthena; Status Code: 400; Error Code: InvalidRequestException; Request ID: 2a99f6eb-b853-407f-b229-d309a4ca3f5c; Proxy: null)"
}

我是 AWS 新手。有人可以帮助我解决如何在 Athena 的 QueryString 参数中传递查询对象的问题吗?

您的 QueryString 键中缺少“.$”注释:

"QueryString.$": "$.query",

[...] The values of [your Parameter fields] can either be static values that you include in your state machine definition, or selected from either the input or the context object with a path. For key-value pairs where the value is selected using a path, the key name must end in .$.

来源:https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters

此外,您应该在第二个状态中添加以下字段,以便在此处明确:

"Type": "Task",
"End": true